-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
淡海水1 天前
01-05-运行时-JIT优化全景-内联去虚拟化边界检查消除GreenTea1 天前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调风流 少年1 天前
Spring AI 2.0:Memory万少1 天前
给 DeepSeek Harness 装个"应用商店":一条命令,595 个插件随你逛波波0071 天前
C# 15 重磅新特性: 带标签 break 与 continue:重新定义嵌套循环控制流wujian83112 天前
怎么用千问生成word文档:从「格式崩」到「一键过」,AI导出鸭打通最后半厘米IT_陈寒2 天前
Python的GIL让我多写了500行代码zlinear数据采集卡2 天前
D223上位机C#开发实战:从帧解析到波形显示的完整实现IT爱学堂2 天前
精讲软件设计师(软考中级)一站式通关课_实战课程_慕课网战天战地站房顶2 天前
在 Windows Docker 中部署 PostgreSQL 17 + pgvector 完整指南