What IHttpActionResult? How to use it?
IActionResult is new interface in ASP.NET Core and it can be used as a return type of action in ASP.NET Core. IActionResult can return all things that ActionResult Suppose to do.
IActionResult and ActionResult work as a container for other action results, in that IActionResult is an interface and ActionResult is an abstract class that other action results inherit from.
In previous version i.e. ASP.NET MVC 5, MVC and API are two seperate things so they have their own return types/values like –
MVC has ActionResult is container for JSonResult,RedirectResult,RedirectToRouteResult etc. can return a View, Redirect,RedirecttoAction etc.
For Web API we where having return type HttpResponseMessage, IHttpActionResult using which you can return a json, xml , objects and http status code.
What ASP.NET Core did is it combined both these things togeaterh into one interface called IActionResult and it can return –
- Status Code Results
- Object Results
- Redirect Results
- Json Results
- File Results
- Content Results