-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
架构师沉默4 分钟前
程序员真的要失业了吗?于先生吖5 分钟前
SpringBoot+Vue 前后端分离短剧漫剧系统开发实战shengjk111 分钟前
我用 EXISTS 把一条 SQL 从 18 秒优化到 6 秒,同事以为我改了索引AskHarries12 分钟前
openclaw对接企业微信森林里的程序猿猿14 分钟前
Spring Aop底层源码实现(一)耗子会飞21 分钟前
小白学习springboot项目如何连接RocketMQZTrainWilliams28 分钟前
swagger-mcp-toolkit 让 AI编辑器 更快“读懂并调用”你的接口cylgdzz11141 分钟前
PageIndex:一种不靠向量检索的长文档 RAG 实现思路Later1 小时前
Apache Doris 深度讲解:从核心概念到实战项目攒了一袋星辰1 小时前
SequenceGenerator高并发有序顺序号生成中间件 - 架构设计文档