码迷,mamicode.com
首页 > Web开发 > 详细

.NET Core MVC 中 Controller 中让页面跳转的方法

时间:2020-06-30 12:55:40      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:logo   cookie   order   sync   context   mvc   rman   control   系统   

  • 方式一:

    在控制器的方法内部结尾使用 return View();  来打开与方法同名的页面,如:

    public ActionResult Login()

    {

           return View();

    }

    该写法打开 Login 页面。

     

  • 方式二:

    可以添加参数来显式地指定要跳转的页面,如:

    return View("Register");

    该写法跳转到系统控制器下的 Register 页面。

     

  • 方式三: 

    使用 RedirectToAction 方法,跳转到指定的控制器的指定页面,如:

    public async Task<IActionResult> Logout()

    {

        await HttpContext.SignOutAsync("Cookies");

        return RedirectToAction("Index", "Home");

    }

    该写法跳转到 Home 控制器的 Index 页面。

     

  • 方式四:

    使用 Redirect 方法,如:

    return Redirect("/Home/Index");  //临时重定向

    return RedirectPermanent("/Home/Index");  //永久重定向

    效果和方式三一样。

     

  • 方式五:

    使用 RedirectToRoute 方法:

    return RedirectToRoute(new { Controller = "Home", Action = "Index", ID = "1" });

     

.NET Core MVC 中 Controller 中让页面跳转的方法

标签:logo   cookie   order   sync   context   mvc   rman   control   系统   

原文地址:https://www.cnblogs.com/yu6688/p/13212777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!