-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
踏浪无痕1 小时前
AI 时代架构师如何有效成长?程序员小假1 小时前
我们来说一下无锁队列 Disruptor 的原理武子康2 小时前
大数据-209 深度理解逻辑回归(Logistic Regression)与梯度下降优化算法maozexijr2 小时前
Rabbit MQ中@Exchange(durable = “true“) 和 @Queue(durable = “true“) 有什么区别源码获取_wx:Fegn08952 小时前
基于 vue智慧养老院系统独断万古他化3 小时前
【Spring 核心: IoC&DI】从原理到注解使用、注入方式全攻略毕设源码_郑学姐3 小时前
计算机毕业设计springboot基于HTML5的酒店预订管理系统 基于Spring Boot框架的HTML5酒店预订管理平台设计与实现 HTML5与Spring Boot技术驱动的酒店预订管理系统开不吃香菜学java3 小时前
spring-依赖注入ja哇3 小时前
Spring AOP 详细讲解南部余额3 小时前
Spring Boot 整合 MinIO:封装常用工具类简化文件上传、启动项目初始化桶