<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