-
方式一:
在控制器的方法内部结尾使用 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 天前
从 cargo-whero 库中,找到提升 rust 的契机keep one's resolveY1 天前
SpringBoot实现重试机制的四种方案阿丰资源1 天前
基于Spring Boot的电影城管理系统(直接运行)IT_陈寒1 天前
SpringBoot自动配置的坑差点让我加班到天亮消失的旧时光-19431 天前
Spring Boot 工程化进阶:统一返回 + 全局异常 + AOP 通用工具包xiaogutou11211 天前
2026年历史课件PPT模板选购指南:教师备课效率与精度的平衡方案追风筝的人er1 天前
SpringBoot+Vue3 企业考勤如何处理法定假期?节假日方案、调休补班与工作日判断链路拆解金銀銅鐵1 天前
[git] 如何丢弃对一个文件的改动?橘子海全栈攻城狮1 天前
【最新源码】养老院系统管理A013smallyoung1 天前
具有反思能力的 Agentic RAG 实战:用 LangChain4j 实现 CRAG 纠错检索