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

相关推荐
MC丶科1 小时前
【SpringBoot常见报错与解决方案】中文乱码?Spring Boot 统一解决前后端中文乱码问题(含 Postman 测试)!别再百度“加 UTF-8”了!
spring boot·后端·postman
XXOOXRT6 小时前
基于SpringBoot的加法计算器
java·spring boot·后端·html5
我是苏苏6 小时前
C#高级:使用ConcurrentQueue做一个简易进程内通信的消息队列
java·windows·c#
moxiaoran57537 小时前
Go语言的错误处理
开发语言·后端·golang
Never_Satisfied8 小时前
C#获取汉字拼音字母方法总结
开发语言·c#
短剑重铸之日12 小时前
《7天学会Redis》特别篇: Redis分布式锁
java·redis·分布式·后端·缓存·redission·看门狗机制
小北方城市网13 小时前
SpringBoot 全局异常处理与接口规范实战:打造健壮可维护接口
java·spring boot·redis·后端·python·spring·缓存
不绝19113 小时前
C#核心:多态
开发语言·c#
hanqunfeng13 小时前
(三十三)Redisson 实战
java·spring boot·后端
小北方城市网14 小时前
SpringBoot 集成 MyBatis-Plus 实战(高效 CRUD 与复杂查询):简化数据库操作
java·数据库·人工智能·spring boot·后端·安全·mybatis