方式一:
在控制器的方法內部結尾使用 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" });