Using ActionResult
In this recipe, you will learn how to use ActionResult to return with a Web API. ActionResult is a core type of MVC for returning a result from server to client. ActionResult is a base class and its abstract, so we can use one of the derived classes of it, such as JsonResult, ViewResult, RedirectResult, or FileResult.
Getting ready
We will create a Web API controller with the CRUD method to understand what ActionResult we have to return for each HTTP verb.
How to do it...
With ASP.NET Core MVC and Web API-merging, the base class is now the same. ActionResults now returns the HTTP status code result, as the ApiController base class returned before ASP.NET Core.
We will use ActionResults to return the HTTP status code with a CRUD Web API controller:
- First, let's create the Web API application by creating an empty web application.
- Next, we will add the ASP.NET Core MVC dependency to the project:
"Microsoft.AspNetCore.MVC": "2.0.0",
- Next, let's add the following code to
Startup.cs...