ActionResult Types in MVC

ActionResult Types in MVC

MVC Controller may have one or more method that have different type of result.

ActionResults: It’s the base class of all result type and this an abstract class.  So as this is base class so it may have any below return type i.e  ViewResult, PartialViewResult and  JsonResult. Based on the requirement we have choose action results.

Types of ActionResults

ActionResult  MVC Helper Method Uses
ViewResult View Renders a specified view to the response stream.
PartialViewResult PartialView Render the specified partial view to response stream.
RedirectResult Redirect For redirection the request to another URL.
RedirectToRouteResult RedirectToRoute Redirect to another action method, determined by the route engine.
ContentResult Content Returns a user-defined content type
JsonResult Json When you want to return a serialized JSON object
JavaScriptResult JavaScript Returns a script that can be executed on the client
FileResult File Returns a binary output to write to the response
EmptyResult (None) returns a null result

Now as per requirement we will need to be select the correct ActionResult Type. Mostly ViewResult, PartialViewResult , JsonResult, and RedirectResult are used.