mvc重定向
阅读原文时间:2023年07月15日阅读:1

出处 : https://www.cnblogs.com/lgxlsm/p/5441149.html

、重定向方法:Redirect / RedirectToAction / RedirectToRoute
复制代码
public class TestController : Controller
{
public ActionResult Index(int id = , 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 = , 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" //子区域

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章