-
方式一:
在控制器的方法内部结尾使用 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 分钟前
Claude Code Tools 研究系列(三)ExitPlanMode星栈25 分钟前
oh-my-pi工程级AI编码工使用体验立心者02 小时前
SpringBoot中使用TOTP实现MFA(多因素认证)AskHarries3 小时前
SEO 页面怎么生成爱吃牛肉的大老虎3 小时前
Rust对象之结构体,枚举,特性石榴3 小时前
NestJS 的请求到底经过了什么:装饰器、守卫、拦截器、管道与中间件如何配合Gopher_HBo3 小时前
moby-client客户端杨运交4 小时前
[055][调度模块]Spring动态任务调度框架的设计与实现卷福同学5 小时前
AI编程出海第二步:验证关键词能否做站西门啐血6 小时前
上位机开发之假装有设备,使用 C# 模拟串口设备