IActionResult Vs ActionResult

IActionResult is an interface and ActionResult is an implementation of that interface.

ActionResults is an abstract class and action results like ViewResult, PartialViewResult, JsonResult, etc., derive from ActionResult.

Let's say you want to create an action result not catered to by MVC, say an XML result.

IActionResult is an interface, we can create a custom response as a return, when you use ActionResult you can return only predefined ones for returning a View or a resource. With IActionResult we can return a response, or error as well. On the other hand, ActionResult is an abstract class, and you would need to make a custom class that inherits.

For example see below,

  1. publicNoContentResultNoContentActionResult() {  
  2.     returnNoContent();  
  3. }  
  4. publicIActionResult NoContentActionResult() {  
  5.     returnNoContent();  
  6. }  
  7. OR  
  8. publicIActionResult JsonActionResult() {  
  9.     returnNotFound();  
  10. }  
  11. publicJsonResult JsonActionResult() {  
  12.     returnNotFound(); // This line will give Error  
  13. }  

From the above examples we can return NoContent() OR NotFound() from IActionResult. But if you want to use such type of return values with ActionResults, you need to use particular ActionResults, NoContentResult And JsonResult.