-
方式一:
在控制器的方法内部结尾使用 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 分钟前
Unity资源加载进化论:从AssetBundle到Addressables,一文带你吃透手游资源管理空山返景32 分钟前
Dify RAG知识库-自部署完整指南苏三的开发日记1 小时前
如何规避死锁该用户已不存在1 小时前
用 Claude Code Agents 与 CI/CD 搭建自动化研发团队(Part 3)豹哥学前端1 小时前
agent智能体经典范式构建胡志辉2 小时前
邮件中点击“加载图片”,你的IP地址已经被泄漏拽着尾巴的鱼儿2 小时前
spring 动态代理Rust研习社2 小时前
Rust 的 move 语义,一次讲透IT_陈寒2 小时前
用了Vue的动态组件之后,我被坑得找不着北aini_lovee3 小时前
C#与倍福PLC(通过ADS协议)通信上位机源程序实现