.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" });

相关推荐
小荷才露尖尖角,早有蜻蜓立上头10 分钟前
SpringBoot 定时任务
java·spring boot·后端
ServBay19 分钟前
AI 请求去哪了?OpenRouter 路由、供应商回退与数据留存
后端·aigc·ai编程
Moment1 小时前
AI 写代码越来越快,程序员为什么反而更累了
前端·后端·面试
apeman1 小时前
git-cherry合并代码工具
前端·后端
行百里er2 小时前
轻量级 Spring 监测工具 Spring Insight 版本进展:Server 2.1.0 + Agent 0.6.0
后端·开源·监控
夜深忽梦少年事G4 小时前
MySQL 排序解析:索引有序扫描、filesort、优先队列
后端
why技术5 小时前
我把这套 skills 引入团队,跑了好几个月后,说点真实体感。
前端·后端·ai编程
zhoulcc5 小时前
前端响应处理:AjaxResult与TableDataInfo的JSON结构区别及统一取值方案
前端·后端·bug·ajaxresult·tabledatainfo
geovindu5 小时前
rust: Timing Functions Pattern
开发语言·后端·设计模式·rust·计时函数模式·性能分析型模式
geovindu6 小时前
python:Lasso
开发语言·后端·python·算法