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

淺唱寂寞╮ 提交于 2019-12-11 05:39:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!