Understanding ActionResult in ASP. NET MVC

Source: Internet
Author: User

Usually we have an ASP. when a Controller is created in the net mvc project, the default return type of the Index () method is ActionResult. by viewing the UML diagram, ActionResult is actually an abstract class, therefore, the type actually returned is the subclass of this abstract class.

 

ØActionResultAnd its subclassUMLFigure

 

The UML diagram of ActionResult and its subclass is as follows:

 

Because the image size is large, it may seem small and inconvenient in the browser. You can click here to download the large image and open it in a professional image browser.

Download big chart

ØActionResultComparison table of its subclass

 

ActionResultSubclass name

Description

ViewResult

HTML page content

EmptyResult

Blank Page Content

RedirectResult

Locate another URL

JsonResult

JSON results that can be applied to AJAX programs

JavaScriptResult

Represents a JavaScript Object

ContentResult

Indicates a text content

FileContentResult

Indicates a file that can be downloaded and binary.

FilePathResult

Indicates a file that can be downloaded and specified path

FileStreamResult

Indicates a downloadable and streaming file.

 

By writing the code, we can easily see the following code:

Public ActionResult Index ()

{

Return View ();

}

Some people may wonder why the returned value is View since I define ActionResult?

In fact, this View type is the subclass of ActionResult ViewResult. For methods and returned objects in the Controller, see the following table:

ControllerMethod in

Returned object

View

ViewResult

Redirect

RedirectResult

RedirectToAction

RedirectToActionResult

RedirectToRoute

RedirectToRouteResult

Json

JsonResult

JavaScriptResult

JavaScriptResult

Content

ContentResult

File

FileContentResult, FilePathResult, and FileStreamResult

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.