.NET Core 2.1 adds area as url parameter

680 Views Asked by At

I'm trying to implement an Area for Administrators within my ASP.Net MVC Core 2.1 application.

I have configured the route for the area as follows:

app.UseMvc(routes =>
        {
            routes.MapRoute(
              name: "areas",
              template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
            );
        });

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

In _Layout.cshtml I have:

<a asp-area="Admin" asp-controller="Admin" asp-action="Index">Admin</a>

In AdminController I have:

[Area("Admin")]
public class AdminController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}

Razor is generating wrong URL not like http://localhost:44327/Admin/Admin/Index but https://localhost:44327/Admin?area=Admin.

0

There are 0 best solutions below