Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created June 2, 2021 14:52
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/f86c8c2c6896e25ec4def979faf155ba to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/f86c8c2c6896e25ec4def979faf155ba to your computer and use it in GitHub Desktop.
.NET Core Web API - Return ActionResult<T> from Actions
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
[HttpPut("{id}")]
public ActionResult<SubjectSummary> Put([FromRoute] int id, [FromBody] SubjectSummary summary)
{
// Hypothetical checks to explain the concept
if (id < 0)
{
return BadRequest();
}
// Hypothetical checks to explain the concept
if (id > 10)
{
return NotFound();
}
// Implicit Conversion to ActionResult<SubjectSummary>
return summary;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment