Saturday 16 November 2013

ASP.Net MVC ActionResult return type

This is just a quick aide-mémoire for me as I pick up some MVC code again. At the time of writing MVC is in version 5.

OK, action methods can return the following ActionResult types:

 

Action Result Helper Method Description

ViewResult

View

Renders a view as a Web page.

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

RedirectToRoute

Redirects to another action method.

ContentResult

Content

Returns a user-defined content type.

JsonResult

Json

Returns a serialized JSON object.

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).

 

See Controllers and Action Methods in ASP.NET MVC Applications for the origin of this table.

Saturday 16 November 2013