-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
我叫黑大帅12 小时前
解决聊天页内部滚轮改为页面滚动问题IT_陈寒13 小时前
Python的线程池居然把我坑在了垃圾回收这块zhangxingchao13 小时前
AI应用开发八:RAG相关技术总结吴佳浩14 小时前
Go史上最大“打脸”现场来了:泛型方法终于实现了Huyuejia14 小时前
runtime-askRust研习社14 小时前
90% 的 Rust 新手都不知道的 3 个实用开发技巧雪豹阿伟14 小时前
15.C# —— 多接口,泛型方法,泛型效率、泛型类和泛型接口、泛型约束影寂ldy14 小时前
C# const 常量 / readonly 只读 / static readonlyZengLiangYi14 小时前
sql.js WASM 深度解析