What is the difference between Microsoft.AspNetCore.Http.IResult
and Microsoft.AspNetCore.Mvc.IActionResult
? Which one should I use when I'm going to build an API? I usually use the Results
class with its methods for that.
IActionResult
is part of the MVC framework. It is found in Microsoft.AspNetCore.Mvc
namespace in the Microsoft.AspNetCore.Mvc.Abstractions.dll
library. Commonly it is used in MVC-based web API implementations. This has existed for quite some time, since around when ASP.NET MVC was first started. It exists in the .NET Framework, and all versions of .NET Core / .NET.
Microsoft Learn: IActionResult Interface
IResult
is part of the new API framework introduced as part of .NET 6.0. It is found in the Microsoft.AspNetCore.Http
namespace in the Microsoft.AspNetCore.Http.Abstractions.dll
library. IResult
is fully supported with the new minimal APIs features of .NET 6.0+.
Microsoft Learn: IResult Interface
No, these interfaces are completely separate, coming from separate namespaces and libraries.
This depends, but generally, if you are working with an MVC-based API controller, you should consider using IActionResult
(or the base ActionResult
class, if desired).
If you are writing APIs without MVC using .NET 6.0+, either using the Minimal API framework or something else, you should consider using IResult
.
Consider using the framework-provided
IResult
-derived classes (TypedResults or Results) instead of theIResult
interface directly 1.
Here are some excellent resources from Microsoft Learn that provide overviews and helpful insights into each of these areas of API development.
Microsoft Learn: Controller action return types in ASP.NET Core web API
Microsoft Learn: ASP.NET Core Fundamentals Overview
Microsoft Learn: Tutorial: Create a minimal API with ASP.NET Core
Microsoft Learn: Tutorial: Create a web API with ASP.NET Core