-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
小飞Coding6 分钟前
MyBatis Mapper 实现原理彻底解密——从动态代理到 JDBC 执行全链路剖析Mr.456717 分钟前
Spring Boot 集成 PostgreSQL 表级备份与恢复实战ZoeJoy817 分钟前
C# + 机器视觉 + AI:从工业相机取图到 YOLO 目标检测的完整工控解决方案LucianaiB17 分钟前
王炸组合!腾讯云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!白露与泡影21 分钟前
探索springboot程序打包docker的最佳方式开心就好202523 分钟前
本地执行 IPA 混淆 无需上传致云端且不修改工程的方案架构师沉默36 分钟前
为什么一个视频能让全国人民同时秒开?掘金码甲哥1 小时前
同样都是九年义务教育,他知道的AI算力科普好像比我多耶sthnyph1 小时前
SpringBoot Test详解