Action Result Return Types in ASP.NET MVC

Action Result Helper Method Description
ViewResult View Renders a view as a Web page.

Example:

Return view for that action method: return View();

Return a different view: return View(“ViewName”);

PartialViewResult PartialView Renders a partial view, which defines a section of a view that can be rendered inside another view.
RedirectResult Redirect Redirects to another action method by using its URL.
RedirectToRouteResult RedirectToAction Or

RedirectToRoute

Redirects to another action method.
ContentResult Content Returns a user defined content type.
Example:
Return a string: return Content(“A plain text”);
Return XML: return Content(“<node/>”,”text/xml”);
JsonResult Json Returns a serialized JSON object.
Example:
Return an object as JSON: return Json(player);
JavaScriptResult JavaScript Returns a script that can be executed on the client.
FileResult File Returns binary output to write to the response.
EmptyResult (None) Represents a return value that is used if the action method must return a null result (void).

Comments 1

Leave a Reply

Your email address will not be published. Required fields are marked *