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