Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created June 2, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/bb810ea076e003677a748742c5383d07 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/bb810ea076e003677a748742c5383d07 to your computer and use it in GitHub Desktop.
.NET Core Web API - Returning IActionResult from Actions
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
[HttpPut("{id}")]
public IActionResult Put([FromRoute] int id, [FromBody] SubjectSummary summary)
{
if(!Exists(id))
{
// NotFound() method returns 404 status code
// NotFoundResult is returned from here.
return NotFound();
}
// Not possible to return specific type
// return summary;
// Ok() method returns OkResult (200OK Status)
return Ok(new { id = id, summary = summary });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment