ivaylokenov / AspNet.Mvc.TypedRouting

A collection of extension methods providing strongly typed routing and link generation for ASP.NET Core MVC projects.
https://mytestedasp.net/
MIT License
485 stars 36 forks source link

Wrong route generated when linking from area to arealess controller #19

Closed justdmitry closed 8 years ago

justdmitry commented 8 years ago

Controller AccountController is located in default (root, non-area specific) part of my site, it has Logout action.

I have area Admin with controllers labeled with [Area("admin")] attribute.

My Startup class contains following code:

app.UseMvc(routes =>
{
    routes.UseTypedRouting();

    routes.MapRoute(
        name: "areaRoute",
        template: "{area:exists}/{controller=Home}/{action=Index}");

    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}");
});

Everything looks correct according to asp.net core docs

Inside view in my Areas/Admin/Views/... I write:

@Url.Action<MyNamespace.Controllers.AccountController>(c => c.Logout()) })

And generated value is /admin/account/logout, which is incorrect. Must be /account/logout, because AccountController does not have Area attribute.

ivaylokenov commented 8 years ago

@justdmitry I will take a look. Providing area route value like in the original helpers methods should workaround this:

@Url.Action(c => c.Logout(), new { area = string.Empty }) })

I believe the magic string overloads will generate the same link - @Url.Action("Logout", "Account") will add the area.

ivaylokenov commented 8 years ago

@justdmitry Package with a fix is now uploaded to NuGet.