-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
DolphinDB2 小时前
告别手写代码:Trae + DolphinDB Skill,10 分钟造一个懂期货的投研 AgentChenNyan2 小时前
从一块 ESP32-S3 开发板到 AI 陪伴设备:我们如何搭建一套可持续演进的端云架构ValueHD2 小时前
视频会议终端是什么,有哪几种类型?.Hypocritical.2 小时前
SpringBoot 各版本 Profile 多环境配置完整对比(2.x/ 2.4+ / 3.x/4.x乐橙开放平台3 小时前
把工地遮挡和掉线接进项目部:setMessageCallback 订 alarm 与 deviceStatus卷无止境4 小时前
FastAPI 的可观测性进化,从打日志到看清整个系统的呼吸MetaLite4 小时前
SpringBoot防重复提交-加一把Redis锁就够吗卷无止境4 小时前
FastAPI 的 CI/CD 之路,从代码提交到线上运行计算机毕设定制辅导-无忧学长4 小时前
《基于SpringBoot的图书管理系统设计与实现》小蒜学长4 小时前
借助于大模型工具Cursor的中药材交易系统的设计与实现(代码+数据库+LW)