-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
冰美式只要糖9 小时前
同一个 Seed,为什么插入另一条请求会改变采样结果?Xmi9 小时前
LLM 多步任务总是漏步骤?一次 Prompt Chaining 改造的完整记录sean_wang129 小时前
Rust 轻量级虚拟机 smolvm 实战:200ms 冷启动、OCI 镜像直跑、单文件打包badhope9 小时前
3 个 Agent 并行发文章:我用 SQLite 任务表止住重复Gopher_HBo9 小时前
手写 cobra 命令树与 FindXmi9 小时前
Windows容器部署EKS:从 Dockerfile 到 CloudFront 的一次打通青山木9 小时前
JVM 类加载全解:Class 文件结构、加载链接初始化与双亲委派考虑考虑11 小时前
EMQX认证回调hryou092212 小时前
10分钟看懂嵌入模型选型:6个维度+1张存储账单Rain的Java大神之路14 小时前
钱扣了,消息却没了:RocketMQ 5.x 事务回查状态到底该放哪?