问题
I recently updated the Visual Studio for Update 3
and ASP.Net Core for 1.0.0.
I followed the tutorial in documentation and I tried set up for use Areas like this https://docs.asp.net/en/1.0.0/mvc/controllers/areas.html
However, the link generated was http://localhost:2187/?area=Admin, instead of http://localhost:2187/Admin/Home/Index
Update
My routes:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "areaRoute",
template: "{area}/{controller=Home}/{action=Index}");
});
What is wrong?
Solution
The problem was in the order of the routes as answer mentioned.
回答1:
This indicates that you do not have a route registered where it takes in an area.
An example of an route for areas:
app.UseMvc(routes =>
{
routes.MapRoute(name: "areaRoute",
template: "{area}/{controller=Home}/{action=Index}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
});
Update:
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.
来源:https://stackoverflow.com/questions/38251414/in-aspnet-core-the-tag-helper-asp-area-doesnt-work