© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
2 replies
prodijay

What return method is appropriate for controller actions for SPA frontend?

I have a basic CRUD app with a React SPA and a Postgres database. I want to know what I should return in the controller actions, specifically for Get, Post, Put and Delete actions. I've inspected some docs like this: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/details?view=aspnetcore-8.0
which use
RedirectToAction
RedirectToAction
. However this doesn't seem like it makes sense to use for a React SPA. I've been unable to find any relevant information on this topic of appropriate return methods for SPA.
Any help would be appreciated.

For instance would it make sense to use the
CreatedAtAction
CreatedAtAction
for my Post controller action? Or could I simply just return
createdNoteDTO
createdNoteDTO
? I want to send the created object back to the frontend.

  [HttpPost("{studyId}")]
  public async Task<ActionResult<NoteDTO>> CreateNote(int studyId, [FromBody] CreateNoteInput input)
  {
    Note newNote = new Note
    {...};

    _context.Notes.Add(newNote);
    await _context.SaveChangesAsync();

    var createdNoteDTO = new NoteDTO
    {...};

    return CreatedAtAction(nameof(CreateNote), new { id = newNote.Id }, createdNoteDTO);
  }
  [HttpPost("{studyId}")]
  public async Task<ActionResult<NoteDTO>> CreateNote(int studyId, [FromBody] CreateNoteInput input)
  {
    Note newNote = new Note
    {...};

    _context.Notes.Add(newNote);
    await _context.SaveChangesAsync();

    var createdNoteDTO = new NoteDTO
    {...};

    return CreatedAtAction(nameof(CreateNote), new { id = newNote.Id }, createdNoteDTO);
  }


Additionally, what should I do regarding the delete action? I don't want to return anything but it seems I have to return something.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ What should web api controller return?
C#CC# / help
4y ago
Method doesnt return
C#CC# / help
3y ago
❔ What is the appropriate way to confirm User ID for API
C#CC# / help
3y ago
Controller-Service architecture. What is service?
C#CC# / help
3y ago