mvc重定向

出处 :  https://www.cnblogs.com/lgxlsm/p/5441149.html
8、重定向方法:Redirect / RedirectToAction / RedirectToRoute
复制代码
    public class TestController : Controller
    {
        public ActionResult Index(int id = 0, string name = "")
        {
            return View();
        }

        //Redirect:直接转到指定的url地址
        public ActionResult Redirect()
        {
            return Redirect("http://www.baidu.com");
        }

        //RedirectToAction:直接使用 Action Name 进行跳转,也可以加上ControllerName
        public ActionResult RedirectResult()
        {
            return RedirectToAction("Index", "Test", new { id = 100, name = "liu" });
        }

        //RedirectToRoute:指定路由(RouteConfig注册的路由规则)进行跳转
        public ActionResult RedirectRouteResult()
        {
            return RedirectToRoute("Default", new { controller = "Test", action = "Index" });
        }
    }
复制代码

//跳转区域下的控制器

return RedirectToRoute("Default", new { area = "Backstage", controller = "Doc", action = "List" }); //
"Default" 主区域 ,
area = "Backstage" //子区域

 

posted @ 2018-07-11 10:45  enych  阅读(297)  评论(0编辑  收藏  举报