-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
问道飞鱼11 分钟前
【Rust编程语言】Rust数据类型全面解析泉城老铁37 分钟前
目前开源架构需要注意的安全问题ZoeGranger42 分钟前
【Spring】IoC 控制反转、DI 依赖注入、配置文件和bean的作用域马卡巴卡44 分钟前
分库分表数据源ShardingSphereDataSource的Connection元数据误用问题分析superman超哥1 小时前
仓颉动态特性探索:反射API的原理、实战与性能权衡骑着bug的coder1 小时前
第7讲:索引(下)——失效场景与优化实战superman超哥1 小时前
仓颉元编程之魂:宏系统的设计哲学与深度实践一 乐1 小时前
健身房预约|基于springboot + vue健身房预约小程序系统(源码+数据库+文档)踏浪无痕1 小时前
JobFlow:时间轮与滑动窗口的实战优化molaifeng2 小时前
像搭积木一样理解 Golang AST