In AspNet.Core the Tag Helper asp-area doesn't

2019-07-23 12:41发布

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条回答
来,给爷笑一个
2楼-- · 2019-07-23 13:31

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.

查看更多
登录 后发表回答