.net的controller中如何让页面跳转

 时间:2026-02-15 11:45:42

介绍了 .NET Core MVC 中 Controller 中让页面跳转的方法。(独立观察员)

工具/原料

VisualStudio

安装VS时安了 .NET Core

方式

方式一:

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

注意事项

要确保控制器和方法是存在的

  • 东风风光580汽车的配件有哪些
  • win7电脑开启承载无线网wlan热点
  • 如何查看驾驶证已处理违章历史记录?
  • 浅谈制怒好方法
  • FPGA开发教程:[3]开发一个与门程序
  • 热门搜索
    热带雨林的作用 人为什么会脸红 captain什么意思 大棚种植什么最赚钱 西咪替丁的功效与作用 monica什么意思 八年级上册地理知识点 什么是种子 10万买什么车好 八珍汤的功效与作用