-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
爱勇宝1 小时前
我做了一个只用来搜歌词的小 AppIT_陈寒2 小时前
SpringBoot自动配置坑了我一晚上,原来问题出在这SelectDB3 小时前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台SelectDB3 小时前
秒级弹性、最高降本 70%:SelectDB Serverless 如何重塑云数仓资源效率PinkSun3 小时前
Spring AI ChatMemory踩坑实录:重启丢数据、Agent丢记忆、对话溢出壹方秘境3 小时前
我用Go语言开发了一个跨平台的HTTPS抓包和调试工具神秘面具男3 小时前
HarmonyOS 6.0跨端远程控制苏三说技术4 小时前
全网爆火的Loop到底是什么?神奇小汤圆4 小时前
Loop Runtime 架构拆解:别再手动催 Agent,先把工程闭环跑起来