-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
猿长大人2 小时前
C# | Serilog 新手入门IT_陈寒2 小时前
Vue的响应式让我原地破防,原来问题出在这思考着亮2 小时前
1.RabbitMQ基本使用XuCoder2 小时前
面试官:Redis 单线程为什么还这么快?这道题答错的人真不少子兮曰3 小时前
Bun vs Node.js 深度对决:跑分快 4 倍,真实业务只剩 3%,2026 年到底该怎么选?码事漫谈3 小时前
把 AI 拆掉,你的系统还能跑吗?在世修行3 小时前
从零打造 C# 工业视觉检测系统(七):串口通信 SerialPort 封装与开发BUG指挥官3 小时前
Sa-Token和Spring Security对比众人皆醒我独醉3 小时前
Token:AI 世界的基本粒子——不是"字",是统计上最优的"字符组合"Java内核笔记4 小时前
Spring Boot 4 拥抱 Jackson 3:包名迁移、配置改名与自动配置源码剖析