MVC controller Common method return type

Source: Internet
Author: User

Common methods of Controller

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;usingSystem.Web.Mvc.Ajax;usingSystem.IO;namespacemvcrazordemo{ Public classDemocontroller:controller {/// <summary>        /// http://localhost: 1847/demo/contentresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Contentresultdemo () {stringContentstring ="contextresultdemo! See the Controllers/democontroller.cs file, which contains the usage of all types ActionResult."; returnContent (contentstring); }        /// <summary>        /// http://localhost: 1847/demo/emptyresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Emptyresultdemo () {return  NewEmptyresult (); }        /// <summary>        /// http://localhost: 1847/demo/filecontentresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Filecontentresultdemo () {//Create a file streamFileStream fs =NewFileStream (Server.MapPath (@"/content/a.jpg"), FileMode.Open, FileAccess.Read); //defines a buffer array            byte[] buffer =New byte[Convert.ToInt32 (fs.            Length)]; Fs. Read (Buffer,0, Convert.ToInt32 (fs.                        Length)); returnFile (Buffer,@"Image/gif"); }        /// <summary>        /// http://localhost: 1847/demo/filepathresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Filepathresultdemo () {//you can export an image in JPG format to GIF format            returnFile (Server.MapPath (@"/content/a.jpg"),@"Image/gif"); }        /// <summary>        /// http://localhost: 1847/demo/filestreamresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Filestreamresultdemo () {FileStream fs=NewFileStream (Server.MapPath (@"/content/a.jpg"), FileMode.Open, FileAccess.Read); returnFile (FS,@"Image/gif"); }        /// <summary>        /// http://localhost: 1847/demo/httpunauthorizedresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Httpunauthorizedresultdemo () {//returns an unauthenticated 401            return NewHttpunauthorizedresult (); }        /// <summary>        /// http://localhost: 1847/demo/javascriptresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Javascriptresultdemo () {returnJavaScript (@"alert ("Test javascriptresultdemo!")"); }        /// <summary>        /// http://localhost: 1847/demo/jsonresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Jsonresultdemo () {varTempobj =New{Controller ="Democontroller", Action ="Jsonresultdemo" }; returnJson (Tempobj,jsonrequestbehavior.allowget); }        /// <summary>        /// http://localhost: 1847/demo/redirectresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Redirectresultdemo () {returnRedirect (@"Http://localhost:1847/Demo/ContentResultDemo"); }        /// <summary>        /// http://localhost: 1847/demo/redirecttorouteresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Redirecttorouteresultdemo () {returnRedirecttoaction (@"Filestreamresultdemo"); }        /// <summary>        /// http://localhost: 1847/demo/partialviewresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Partialviewresultdemo () {returnPartialview (); }        /// <summary>        /// http://localhost: 1847/demo/viewresultdemo/// </summary>        /// <returns></returns>         PublicActionResult Viewresultdemo () {//If no view name is passed in, the view page with the same action name is searched by default.            returnView (); }    }}

MVC controller Common method return type

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.