【发布时间】:2020-02-03 11:24:35
【问题描述】:
我开始使用 ASP.Net core 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/?
【问题讨论】:
-
我能问一下
area:exists应该在做什么吗,不应该只是{area}吗? -
其记录为 exists 应用了路由必须匹配区域的约束
-
我认为你必须从路由模式中去掉
area:"{controller}/{action}/{id}"。然后return RedirectToAction("Index", "Test", new { Area = "Foo" });应该可以工作。 -
尝试定义新的
MapRoute并使用RedirectToRoute而不是RedirectToAction -
如果我删除 {area:exists} 则它可以工作(可能与控制器名称匹配)但它仍将区域显示为查询字符串,并且还允许 localhost:44390/Test
标签: c# asp.net-core asp.net-core-mvc