ActionResult and mvcactionresult of asp.net mvc

Source: Internet
Author: User

ActionResult and mvcactionresult of asp.net mvc

After the Web server receives a client request, it will respond to the request, and the Response is controlled by Response,

However, in asp.net mvc, this part of work is completed by ActionResult,

ActionResult is an abstract class, so the specific work is still completed by many sub-classes,

Specific subclasses include:

EmptyResult, ContentResult

(Content, ContentEncoding, and ContentType are used to set the returned Content, character encoding format, and media type respectively ),

FileResult (FileContentResult, FilePathResult, FileStreamResult ),
<P> Use this area to provide additional information. </p> <a href = "@ Url. action ("ImagePath1", new {id = "1"}) "> download </a>    

 

Public ActionResult ImagePath (string id) {string path = Server. mapPath ("/images/" + id + ". jpeg "); return File (path," image/jpeg ");} public ActionResult ImagePath1 (string id) {string path = Server. mapPath ("/images/" + id + ". jpeg "); return File (path," image/jpeg "," Download ");} public ActionResult ImageContent (string id) {string path = Server. mapPath ("/images/" + id + ". jpeg "); byte [] heByte = null; using (FileStream fsRead = new FileStream (path, FileMode. open, FileAccess. read) {int fsLen = (int) fsRead. length; heByte = new byte [fsLen]; int r = fsRead. read (heByte, 0, heByte. length);} return File (heByte, "image/jpeg");} public ActionResult ImageStream (string id) {string path = Server. mapPath ("/images/" + id + ". jpeg "); FileStream fsRead = new FileStream (path, FileMode. open, FileAccess. read); return File (fsRead, "image/jpeg ");}

 

JavaScriptResult,

Return a piece of js, and the media type is application/x-javascript,

JsonResult,

Json data is returned. The default ContentType is Application/json.

HttpStatusCodeResult,

Specifically, the output is completed by setting StatusCode and StatusDescription of response.

RedirectResult, RedirectToRouteResult,

Internal operations are completed through Response's Redirect/RedirectPermanent,

Redirectresult has two attributes: permanent and URL. The URL can be an absolute or relative address. permanent determines whether the redirection is temporary or permanent,

The difference between the two redirection methods is that the search engine will update its own index based on the permanent redirection,

Compared with RediretResult, RedirectToRouteResult calculates the URL value based on the route,

Therefore, RedirectToRouteResult does not have the URL attribute, but contains the RouteName and RouteValues attributes,

ViewResult.

ViewResult is a special ActionResult, but it is also the most complex

Related Article

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.