-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
行百里er6 小时前
Redis 完结篇——Redis 热点问题在 Spring Boot 项目中实战高频因子挖掘机7 小时前
只取最近 60 个交易日,却每次拉全历史:量化脚本变慢的原因与改法孟健8 小时前
从5000亿Token到83%字节匹配:AI逆向工程与重构的工程闭环实践码事漫谈9 小时前
丢得静悄悄,谈一谈 Agent 的记忆是怎么没的迪飞特科技9 小时前
智慧物业平台实战:Spring Boot 整合小程序实现报修巡检费用全流程考虑考虑9 小时前
@JsonInclude注解使用IT_陈寒9 小时前
Vite的这个问题坑了我三天,原来如此解决!网易云信9 小时前
大模型能上岗做销售吗?我们让 12 款国产模型交了 420 份作业CCblandy9 小时前
HTTP 长连接 3 类故障实测:[WinError 10053]、99 个 TIME_WAIT、69 次多余握手,4 种对策怎么选蜗牛互联网9 小时前
Python Agent工具调用的白名单、参数校验与审批门禁