Asp.net MVC three actionresult return other values

Source: Internet
Author: User

1. Return to the. ascx page

1. Create an action

 

Public actionresult ascx ()
{
Return partialview (); // return some views
}

2. Create a View File

Then, access the display result through http: // localhost: 4116/admin/ascx.

Ii. return text content

Public actionresult text ()
{
Return content ("this is a piece of text ");
}

3. Return a serialized JSON result

Public actionresult showjson ()
{
Mvcapplication2.models. member M = new mvcapplication2.models. Member ();
M. Name = "James ";
M. Sex = "male ";
M. Age = "24 ";
Return JSON (m );
}

Output result {"name": "ZOU Jian", "sex": true} Note: This is not verified.

4. Output JS files

Most JS files are static files, but sometimes JS files may need to be dynamically generated. In this case, we can output

        public ActionResult Js()        {            return JavaScript("var x=0;");        }

We can access it to get a normal page, but its content-type: Application/X-JavaScript; charset = UTF-8

V. page Jump

1. Jump to URL

        public ActionResult rdurl()        {            return Redirect("http://www.baidu.com");        }

2. Jump to action

        public ActionResult rdaction()        {            return RedirectToAction("Index","Eice");        }

3. Jump to the routing rule

Public actionresult rdrouting () {return redirecttoroute ("default", // route name New {controller = "eice", Action = "Index "});}
6. Display files
Public actionresult FN () {return file ("/content/site.css" // file path, "text/CSS" // file type );}

Previous Article: ASP. net mvc two actionresult Return Value

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.