This series of articles is to discuss the Action Results for ASP.NET (Core) MVC and Web API.
- Controller Action Result (1), in ASP.NET MVC
- Controller Action Result (2), in ASP.NET (Core) MVC
- Controller Action Result (3), in ASP.NET Web API
- Controller Action Result (4), in ASP.NET (Core) Web API --- this article
This article discusses Controller Action Results for ASP.NET MVC.
A - Introduction
This article is a following up for the previous article, Controller Action Result (1), in ASP.NET MVC to cover the situation of ASP.NET Core MVC. This article actually has the same conclusion as previous one, with emphasis to Core situation. This article will include the following content:
- A - Controller
- B - Controller Action Workflow
- C - Action Results (Core)
- ActionResult Classes (Core)
- ActionResult Categories (Core)
- All Types of Action Methods in ASP.NET Core MVC
B - Controller Action Workflow
Action Results
An action result is what a controller action returns in response to a browser request.
MVC framework includes various Result classes, which can be returned from an action method. The result classes represent different types of responses, such as HTML, file, string, JSON, javascript, etc. The following list all the result classes available in ASP.NET MVC, ASP.NET Core MVC, ASP.NET Web API, and ASP.NET Core Web API.



- Action Results in Web API 2 --- MS, ASP.NET Web API

- Types Of Web API Action Results --- c-sharpcorner


- All about types of Action Results in the Web API --- Dhananjay
- void
- HttpResponseMessage
- IHttpActionResult
- Other types, such as IEnumerable, object, collections, etc.

- IHttpActionResult vs HttpResponseMessage - Geeksblood
- In web API 1, We have a type called HttpResponseMessage for returning Http response message from action method. It is easy to use but it implicates a lot of smaller details to create a response and some extra code on the controller.
- In Web API 2, IHttpActionResult comes as a new feature which is basically the replacement of HttpResponseMessage. It creates a clean code and allows extensibility of the type of response that we create.
Advantages of using the IHttpActionResult:
- It simplifies unit testing of controllers.
- It moves the common logic for creating HTTP responses into separate classes.
- It makes the controller action method clearer, by hiding the low-level details of constructing the response.
- IHttpActionResult contains a single method, ExecuteAsync, which asynchronously creates an HttpResponseMessage instance.
- The advantages of IHttpActionResult in Web API 2
Web API 2 introduced the new interface IHttpActionResult to return back REST responses, where Web API 1 was using the class HttpResponseMessage to represent HTTP response, and HTTPResponseException to represent HTTP response error.
IHttpActionResult allows developers to enhance their Web API 1 code to be :
- More testable.
- More reusable.
- Cleaner, and more elegant.
We are going to unleash the potential of this interface and see some creative ideas on how to use it.
- Kill Your Tech Interview (Web API) --- fullstack.cafe


References:
- What are the various return types of a controller action in C# ASP.NET WebAPI? (tutorialspoint.com)
- Types Of Web API Action Results (c-sharpcorner.com)
- Action Results in Web API 2 - ASP.NET 4.x | Microsoft Learn
- ASP.NET Web API - ASP.NET 4.x | Microsoft Learn
- What's New in ASP.NET Web API 2.2 | Microsoft Learn
- HttpResponseMessage Class (System.Net.Http) | Microsoft Learn
- System.Net.Http Namespace | Microsoft Learn
- Get Started with ASP.NET Web API 2 (C#) - ASP.NET 4.x | Microsoft Learn
- All about types of Action Results in the Web API – Dhananjay Kumar (debugmode.net)

Join the conversation! Your thoughts help the community grow.