-
方式一:
在控制器的方法内部结尾使用 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 控制器中页面跳转
技术拾荒者2024-11-06 11:54
相关推荐
打工仔折腾 AI7 小时前
工业场景下时序库与实时计算一体化架构选型实践对比蜗牛互联网7 小时前
长任务多Agent共享文件系统的Manifest交接模式苏supper9 小时前
Spring Boot多环境配置与打包运行geovindu9 小时前
rust: Composite Patternsamble10 小时前
从零搭建灌装监控系统(十):生产追溯,条码触发自动记录SearchMan10 小时前
还有人不知道&和&&的区别?想用offer打牌10 小时前
Personal Agent爆火 - 它到底是个什么IT_陈寒10 小时前
Vue的v-if和v-for混用居然是个天坑打工仔折腾 AI12 小时前
从Attention到BERT:双向预训练语言模型到底解决了什么问题lizhongxuan13 小时前
Agent Sandbox: Firecracker 任务生命周期