MVC Action Result Return Types

Afetr This :- asp-net-mvc-request-lifecycle

Who decides to show a view in MVC ?

This is controller’s job to tell the ASP.NET MVC  Framework what it should do next, but not how to do it. This communication occurs through the use of +ActionResult+s, the return values which every controller action is expected to provide.

For example, when a controller decides to show a view, it tells the ASP.NET MVC  Framework to show the view by returning a ViewResult. It does not render the view itself.

There are different types of results that are available to you in ASP.NET MVC-4. When creating new controllers, they will come with one or more actions by default.The Empty controller includes an Index action with a return value of type ActionResult.  ActionResult class is the base class for all action results.There are different ActionResult types are there,briefly explained below.

Content():
Returns a ContentResult that renders arbitrary text, e.g., “Hello, world!”

File() :
Returns a FileResult that renders the contents of a file, e.g., a PDF. HttpNotFound() Returns an HttpNotFoundResult that renders a 404 HTTP status code response.

JavaScript():  
Returns a JavaScriptResult that renders JavaScript, e.g., “function hello() { alert(Hello, World!); }”.

Json():
Returns a JsonResult that serializes an object and renders it in JavaScript Object  Notation (JSON)
format, e.g., “{ “Message”: Hello, World! }”.

PartialView() :
Returns a PartialViewResult that renders only the content of a view (i.e., a view without its layout).

Redirect():
Returns a RedirectResult that renders a 302 (temporary) status code to redirect the user to a given URL, e.g., “302 http://www.XYZ.com/abc”. This
method has a sibling, RedirectPermanent(), that also returns a RedirectResult, but uses HTTP status code 301 to indicate a permanent redirect rather than a temporary one.

RedirectToAction() and RedirectToRoute() :
Act just like the Redirect() helper, only the framework dynamically determines the external URL by querying the routing engine. Like the Redirect() helper, these two helpers also have permanent redirect variants: RedirectToActionPermanent() and RedirectToRoutePermanent().

View():
Returns a ViewResult that renders a view. As you can tell from this list, the framework provides an action result for just about any situation you need to support, and, if it doesn’t, you are free to create your own!
Programming is easy….