问题描述
我最近将 Visual Studio 更新为 Update 3
,并将 ASP.Net Core 更新为1.0.0.
I recently updated the Visual Studio for Update 3
and ASP.Net Core for 1.0.0.
我遵循了文档中的教程,我尝试设置使用区域,例如 https://docs.asp.net/en/1.0.0/mvc/controllers/areas.html
但是,生成的链接是 http://localhost:2187/?area = Admin ,而不是 http://localhost:2187/Admin/Home/Index
However, the link generated was http://localhost:2187/?area=Admin, instead of http://localhost:2187/Admin/Home/Index
更新
我的路线:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "areaRoute",
template: "{area}/{controller=Home}/{action=Index}");
});
怎么了?
解决方案
问题出在所回答路线的顺序上.
The problem was in the order of the routes as answer mentioned.
推荐答案
这表示您没有在区域中注册的路线.
This indicates that you do not have a route registered where it takes in an area.
区域路线示例:
app.UseMvc(routes =>
{
routes.MapRoute(name: "areaRoute",
template: "{area}/{controller=Home}/{action=Index}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
});
更新:
您必须重新排列路线,因为在这种情况下,第一个路线将被匹配.我建议您看一下路由文档,以了解为什么顺序很重要.
You must reorder the routes as in this case the first route would be matched. I would suggest to take a look at the routing docs to know why the order is important.
这篇关于在AspNet.Core中,标记助手asp区域不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!