-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
掘金码甲哥19 分钟前
当对话模型遇上向量模型,vllm production stack 又该如何应对?传奇开心果编程43 分钟前
【springboot基础语法学与练】第 1 课:从零开始IT_陈寒1 小时前
Java线程池用错参数,我的服务居然悄悄崩溃了光影少年1 小时前
Express 中间件原理aramae2 小时前
MySQL内置函数(7)徐小夕3 小时前
存量.doc 文档怎么办?JitWord 开源转换库打通旧文档到在线协同全链路ee又momo3 小时前
一次 JWT Token 过期续期的踩坑记录二月龙3 小时前
App 瘦身实战:图片、so 库、资源压缩,安装包体积减小 40%大勇前进3 小时前
Kotlin 协程实战避坑:90% 的人都会踩的生命周期泄漏问题苏三说技术4 小时前
Spring AI、LangChain4j、AgentScope、Embabel,哪个AI框架更好?