-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
万少24 分钟前
DeepSeek 昨晚刚开源了 Harness:附万少的2 万字保姆级教程大鸡腿同学4 小时前
身弱体质|你的 FM 该关了📻Csvn5 小时前
📊 SQL 入门 Day 18:索引原理Csvn5 小时前
🐍 Day3 : Python 容器精讲 — list、dict、set、tuple 底层实现与高级操作用户938515635075 小时前
ESLint 代码规范完全指南——从 AST 原理到 flat config 逐行解析用户938515635075 小时前
深入理解 Next.js:从 SPA 的 SEO 问题到约定式路由与 SSR 原理码事漫谈7 小时前
Deepseek涨价了,前后对比,竟然差这么多rockey6278 小时前
基于AScript的Lua脚本语言发布啦东风破_8 小时前
大前端手里的 Next.js:从 #root 到 SEO,一份 HTML 的两种命运IT_陈寒9 小时前
Vue的v-for不听话?我被这个Key的坑整懵了