c# - 控制器位于区域中的 RedirectToAction
问题描述
我开始使用 ASP.Net 核心 MVC 3.1 并有一个名为Foo的区域:
endpoints.MapAreaControllerRoute(
name: "Foo",
areaName: "Foo",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
在这个区域中,一个名为Test的控制器带有一个Index操作:https://localhost:44390/Foo/Test/
- 这很好用。
我正在尝试从另一个控制器重定向到这个
return RedirectToAction("Index", "Test", new { area = "Foo" });
但这是送我去https://localhost:44390/Test?area=Foo
我如何使用RedirectToAction()
以结束https://localhost:44390/Foo/Test/
?
解决方案
当放置在默认路由之后时,我会重现您的问题。MapAreaControllerRoute
因此,要解决它,您的区域路由配置必须放在第一位。
app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute(
name: "Foo",
areaName: "Foo",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
推荐阅读
- javascript - JS Array Reduce 的好奇反应
- python - 用 0 填充缺失的日期(天)值
- pandas - 用于除法的熊猫数据框操作为 0
- mysql - 从 2 个表创建 mysql 视图,第一个表列值和第二个表列值应该匹配
- python - 如何在 django 中按类别过滤
- android-studio - Android Studio 突出显示代码红色且没有错误(Gradle 4.0.0 错误)
- excel - 尝试从 Excel 中的 Google 表格复制“IMAGE()”函数
- php - 试图获取非对象的属性 [LARAVEL]
- java - 如何按降序对 TreeMap 值进行排序以及如何限制输出?
- sql - Oracle SQL XML 提取