.net core mvc 控制器中页面跳转

  • 方式一:

    在控制器的方法内部结尾使用 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" });

相关推荐
楚兴24 分钟前
Go + Eino 构建 AI Agent(一):Hello LLM
人工智能·后端
一个处女座的程序猿O(∩_∩)O1 小时前
Go语言Map值不可寻址深度解析:原理、影响与解决方案
开发语言·后端·golang
用户579854769712 小时前
01:系统架构全景:CountBot 多层模块化设计解析
后端
yhyyht2 小时前
Apache Camel 框架入门记录(一)
后端
fchampion2 小时前
最终一致性
java·spring·rabbitmq·github·mvc
rfidunion3 小时前
springboot+VUE+部署(13。创建多表查询)
vue.js·spring boot·后端
今心上4 小时前
spring中的@Autowired到底是什么
java·后端·spring
无心水4 小时前
【任务调度:数据库锁 + 线程池实战】4、架构实战:用线程池 + SKIP LOCKED 构建高可用分布式调度引擎
人工智能·分布式·后端·spring·架构
fdc20175 小时前
解耦的艺术:用责任链模式构建可插拔的文件处理流水线
c#·.net·责任链模式
bugcome_com5 小时前
【C# 数组详解】Array 定义、初始化、遍历、内存原理与面试高频问题
后端·c#·asp.net