ASP. NET MVC page tuning and passing parameters

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/zhensoft163/article/details/7174661

People who have used ASP. NET MVC know that there are several types of page jumps that are commonly used in the page background in MVC, such as: Return View (), Return redirecttoaction ()

Generally we return this page, so use return View () can solve the problem, but many times we will also encounter the return page is not this page, then we will use the following two kinds, but if we return the page when the results of the operation will be returned, We are going to use the return Redirecttoaction () method for expansion.

Redirecttoaction (string actionname); Redirecttoaction (String ActionName, Object viewData); Redirecttoaction (String actionname, string controllername); Redirecttoaction (String actionname, String controllername, Object viewData);


For example use:

1, jump to the same controller inside the different action, such as: HomeController inside the different pages jump to the Index page, redirecttoaction ("Index");

2, jump to the same controller inside the different action, including parameters, such as: HomeController inside the different pages jump to the Index page, and pass msg= "Operation Success", Redirecttoaction ("Index", new { Msg= "Operation succeeded"});

3, jump to different controller inside the different action, such as: Other controller inside the page jump to HomeController inside the Index page, redirecttoaction ("Index", "Home");

2, jump to different controller inside the different action, including parameters, such as: Other controller inside the page jump to HomeController inside the index page, and pass msg= "Operation Success", Redirecttoaction ("Index", "Home", new {msg= "Operation succeeded"});

Passing multiple parameters is similar:

Redirecttoaction ("Index", "Home", new {msg= "Operation succeeded", name= "admin"});

Of course, to use the pass parameter, the parameter name is to be configured in the Global.asax, do not forget.

ASP. NET MVC page tuning and passing parameters

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.