-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
陈随易39 分钟前
Postman 被曝自动往 Claude Code 和 Codex 装插件云-缩影2 小时前
拆解 AI 图像生成应用的后端架构:ECS、OSS 和大模型 API 怎么配合考虑考虑4 小时前
Posrgresql恢复.backup文件无奈何杨4 小时前
风控决策系统决策流,策略模式,权重、顺序、投票、最坏Patrick_Wilson5 小时前
Go 为什么需要 defer?从函数怎么收尾说起苏三说技术5 小时前
DeepSeek Harness入驻B站,评论区被干成了大型插件集市!橙序员小站5 小时前
我一句话让 AI 把公众号工作台搭完了:部署实测记录Patrick_Wilson6 小时前
从文本输出理解 Go 方法与接口QCoding6 小时前
企业级Agent Evaluation实战:Agent能跑就能上线?AI Agent到底怎么测?苍何7 小时前
让 WorkBuddy 操控浏览器,干活有点猛啊1