-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
阳光是sunny28 分钟前
LangGraph实战教程:defer延迟节点——让收尾工作自动排到最后前端工作日常29 分钟前
我学习到的Java中domain和dto区别kite012131 分钟前
Go语言Map深度解析与最佳实践阳光是sunny1 小时前
LangGraph实战教程:控制流详解hold?fish:palm2 小时前
kv存储主从复制的设计与实现swipe3 小时前
07|(前端转后全栈)为什么后端也要缓存?从前端缓存思维理解 Redis952363 小时前
Docker - 基础swipe3 小时前
06|(前端转后全栈)登录后端到底在做什么?JWT、Spring Security 和权限链路吴可可1233 小时前
C#用OpenCVSharp提取轮廓生成CAD多段线