Vnuuk Vnuuk - 1 month ago 11x
C# Question

IActionResult misunderstanding

I just downloaded music store (microsoft sample projct) source code that based on ASP.NET 5. I don't understand there why developers from Microsoft use IActionResult interface as a return type in controllers.

What is a reason of IActionResult interface usage? Why don't just use ActionResult type.

enter image description here


See this post about IActionResult vs. ActionResult:

IActionResult allows a wider range of return types, including any custom code that implements the IActionResult interface. ActionResult is limited only to those classes which extend the ActionResult abstract class (which you could also do with custom code, but using an interface allows for something like multiple inheritance, while extending a class does not).