MVC page redirection is mainly in the following ways:
1.response.redirect (); method
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Mvcdemo.controllers
{
[handleerror] public
class Homecontroller:controller
{
Public ActionResult Index ()
{
viewdata["message"] = "Welcome to use ASP.net mvc!";
Response.Redirect ("User/news");
return View ();
}
Public ActionResult About ()
{return
View ();
}
}
}
2.Return Redirect () method
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Mvcdemo.controllers
{
[handleerror] public
class Homecontroller:controller
{
public ActionResult Index ()
{
viewdata["message"] = "Welcome to use ASP.net mvc!";
Return Redirect ("User/news");
Public ActionResult About ()
{return
View ();
}
}
}
3.Return redirecttoaction () method
This method has two kinds of overloads (the specific several can not remember clearly, even if two kinds of bar) are as follows
Redirecttoaction ("ActionName");//The method is written directly to the page, provided that the page is asked under the change controller, such as the preceding index.aspx, and About.aspx
redirecttoaction (" ActionName "," controllername ")//The method is written directly to ActionName and Controllername, subject to a change in the controller under the question page such as the front of the index.aspx, and About.aspx
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Mvcdemo.controllers
{
[handleerror] public
class Homecontroller:controller
{
Public ActionResult Index ()
{
viewdata["message"] = "Welcome to use ASP.net mvc!";
Return redirecttoaction ("News", "User");
}
Public ActionResult About ()
{return
View ();
}
}
}