-
方式一:
在控制器的方法内部结尾使用 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
相关推荐
沙湖遇雨14 分钟前
8.ByteBuf 的数据模型、生命周期和内存分配by组态18 分钟前
Ricon组态系统API参考手册再吃一根胡萝卜34 分钟前
Agent 如何选择与生成 SQL —— Text2SQL 全链路详解苍何37 分钟前
把操作流程直接录成 Skill,豆包太夯了!Go_error1 小时前
在 Go 服务层中如何优雅地管理事务?爱读源码的大都督1 小时前
DeepSeek面试官问:多租户 RAG 系统怎样实现细粒度权限控制?苍何1 小时前
我们终于成立了 AgentWork 开源社区,16.4 万字豆包工作蓝皮书同步开源(建议收藏)软件黑马王子2 小时前
20.Resources资源加载:基本实现