-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
八苦8 分钟前
MCP 企业托管授权(Enterprise-Managed Authorization)用户9385156350720 分钟前
Node.js 路径与文件系统:从基础到异步进化之路ctrl_v助手41 分钟前
C#表达题笔记一tiao咸鱼1 小时前
前端转 agent # 03 - Pydantic v2 数据校验深入一路向北North1 小时前
Spring Security OAuth2.0(18):资源服务测试用户99045017780091 小时前
若依工作流主流方案对接触底反弹1 小时前
🚀 Node.js path 和 fs 模块,从回调地狱到 async/await 的进化之路!Csvn2 小时前
Python 开发技巧 · 生成器(Generator)进阶 —— 从 yield 到 yield from,写出省内存的生产者-消费者模式geovindu2 小时前
CSharp: Dijkstra Algorithms公子小六3 小时前
基于.NET的Windows窗体编程之WinForms图像控件