-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
为思念酝酿的痛2 小时前
POSIX信号量小羊在睡觉2 小时前
力扣84. 柱状图中最大的矩形周杰伦fans3 小时前
C# 踩坑 CS8370:Switch Expression 在 C# 7.3 不可用及三种解决方案swipe3 小时前
Neo4j + Graph RAG 医疗知识图谱工程实践:患者教育问答真正需要的是“关系可追溯”源码宝4 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展金銀銅鐵4 小时前
[Java] 如何理解 class 文件中方法的 descriptor?村口张大爷4 小时前
05 — 分层架构与依赖倒置z落落5 小时前
C# ToCharArray + foreach遍历 + String与StringBuilderJasonakeke6 小时前
SpringBoot自动配置原理揭秘xiaoshuaishuai86 小时前
C# AvaloniaUI动态显示图片