Created
June 2, 2021 14:52
-
-
Save manoj-choudhari-git/f86c8c2c6896e25ec4def979faf155ba to your computer and use it in GitHub Desktop.
.NET Core Web API - Return ActionResult<T> from Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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