An introduction to ActionResult in MVC

Source: Internet
Author: User

ActionResult is the result type returned after the Controller method executes, the Controller method can return a type that inherits directly or indirectly from the ActionResult abstract class, if the returned non-actionresult type, The controller will convert the result to a contentresult type.



ActionResult derived class diagram


650) this.width=650; "title=" 20140719000923272.gif "alt=" wkiom1pprhera3ntaacet_hfr9o676.gif "src=" http:// S3.51cto.com/wyfs02/m02/40/af/wkiom1pprhera3ntaacet_hfr9o676.gif "/>




Second, several common ActionResult


1,Contentresult


Returns simple plain text content that specifies the type of answer document through the ContentType property, and specifies the character encoding of the answer document through the ContentEncoding property. The Contentresult object is easily returned by the content method in the Controller class. If the Controller method returns a non-ActionResult object, MVC will simply produce a Contentresult object based on the ToString () content of the returned object.



2,Emptyresult

Returns an empty result. If the Controller method returns a NULL,MVC, convert it to a Emptyresult object.



3,Redirectresult

Represents a connection jump, which is equivalent to the Response.Redirect method in ASP. The corresponding controller method is redirect.



5,ViewResult:

Represents a view result that produces an answer based on a view template. The corresponding Controller method is view.



8,Javascriptresult:

is essentially a textual content, just set Response.ContentType to Application/x-javascript, This result should be used in conjunction with the Microsoftmvcajax.js script, after the client receives an AJAX response, it will determine the Response.ContentType value, if it is application/x-javascript, The return response is executed directly by Eval. The Controller method corresponding to this result type is JavaScript.



9,Jsonresult:

Represents a JSON result. MVC sets Response.ContentType to Application/json and serializes the specified objects into JSON representations through the JavaScriptSerializer class. It is important to note that MVC does not allow GET requests to return JSON results by default, to remove this restriction, and to set its Jsonrequestbehavior property to Jsonrequestbehavior.allowget when generating a Jsonresult object. The Controller method corresponding to this result is JSON.




Reference: ActionResult http://www.studyofnet.com/news/518.html in MVC


This article is from the "Learning also leisure" blog, please be sure to keep this source http://studyofnet.blog.51cto.com/8142094/1445050

An introduction to ActionResult in MVC

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.