Controller-various actionresult

Source: Internet
Author: User

<1>

MVC notes Controller related technologies

Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. MVC; using system. web. MVC. ajax; using system. io; namespace demorc. controllers {public class democontroller: controller {// <summary> /// http: // localhost: 1847/demo/contentresultdemo /// </Summary> /// <returns> </returns> Public actionresult contentresultdemo () {string contentstring = "contextresultdem O! Please refer to controllers/democontroller. CS file, which contains all types of actionresult usage. "; return content (contentstring);} // <summary> // http: // localhost: 1847/demo/emptyresultdemo /// </Summary> /// <returns> returns an empty result </returns> Public actionresult emptyresultdemo () {return New emptyresult (); // empty method} // <summary> // http: // localhost: 1847/demo/filecontentresultdemo /// </Summary> /// <returns> return a byte array as a file to the foreground. </returns> Public actionresult filecontentresultdemo () {// initialize a file stream (that is, create a file stream) filestream FS = new filestream (server. mappath (@ "/resource/images/1.gif"), filemode. open, fileaccess. read); // defines an array. The length of this array is the length of the file stream. byte [] buffer = new byte [convert. toint32 (FS. length)]; // read the file "1.gif" to the FS in the buffer array. read (buffer, 0, convert. toint32 (FS. length); Return file (buffer, @ "image/GIF");} // <summary> // http: // L Ocalhost: 1847/demo/filepathresultdemo /// </Summary> /// <returns> Returns a file path to the foreground </returns> Public actionresult filepathresultdemo () {// You can output an image in JPG format as the return file (server. mappath (@ "/resource/images/2.jpg"), @" image/GIF ");} // <summary> // http: // localhost: 1847/demo/filestreamresultdemo /// </Summary> /// <returns> returns the stream of a file to the foreground </returns> Public actionresult filestreamresultdemo () {filestream FS = new filestream (server. mappath (@ "/resource/images/1.gif"), filemode. open, fileaccess. read); Return file (FS, @ "image/GIF");} // <summary> // http: // localhost: 1847/demo/httpunauthorizedresultdemo /// </Summary> // <returns> returns an unverified result. 401 </returns> Public actionresult httpunauthorizedresultdemo () {return New httpunauthorizedresult ();} // <summary> // http: // localhost: 1847/demo/javascriptre Sultdemo /// </Summary> /// <returns> </returns> Public actionresult javascriptresultdemo () {return JavaScript (@ "alert (" "test javascriptresultdemo! ""); // <Summary> // http: // localhost: 1847/demo/jsonresultdemo /// </Summary> /// <returns> Returns a JSON result </returns> Public actionresult jsonresultdemo () {var tempobj = new {controller = "democontroller", Action = "jsonresultdemo"}; return JSON (tempobj) ;}/// <summary> // http: // localhost: 1847/demo/redirectresultdemo /// </Summary> // <returns> </returns> Public actionresult redirectresultdemo () {return redirect (@ "http: // localhost: 1847/demo/contentresultdemo ");} // <summary> // http: // localhost: 1847/demo/redirecttorouteresultdemo /// </Summary> // <returns> </returns> Public actionresult redirecttorouteresultdemo () {return redirecttoaction (@ "filestreamresultdemo ");} /// <summary> /// http: // localhost: 1847/demo/partialviewresultdemo /// </Summary> // <returns> </returns> Public actionresult partialviewresultdemo () {return partialview ();} /// <summary> /// http: // localhost: 1847/demo/viewresultdemo /// </Summary> /// <returns> </returns> Public actionresult viewresultdemo () {// if the view name is not input, by default, view pages with the same name as action are found. return view ();}}}

Zookeeper

Controller-various actionresult

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.