Nouman Bhatti
Nouman Bhatti

Reputation: 1421

Why I have to put Controller name twice in URL to see the view?

I'm make application in .net Core MVC. The MapRoute code in startup.cs is like this

app.UseMvc(routes =>
  {
    routes.MapRoute(name: "AreaRoute",
      template: "{area:required}/{controller:required}/{action}/{id?}",
      defaults: new { area = "Dashboard", controller = "Dashboard", action = "Index" });

    routes.MapRoute(name: "adminRoute",
      template: "{area:required}/{controller:required}/{action}/{id?}",
      defaults: new { area = "Account", controller = "Account" });
    routes.MapRoute(
      name: "ControllerRoute",
      template: "{controller:required}/{action}/{id?}",
      defaults: new { area = "Dashboard", controller = "Dashboard", action = "Index" });
  });

I created areas for each section of my application like this.

enter image description here

My Question is why i need to mention controller name twice in URL to see the view like this

http://localhost:54656/Account/account/Login?ReturnUrl=%2F

Upvotes: 0

Views: 586

Answers (1)

johnny 5
johnny 5

Reputation: 21015

Why are you including routes where the area is required, if you don't need the areas and just want to reference your api via Controller/Action/Id

then just use this

app.UseMvcWithDefaultRoute();

or alternatively remove your the referenced area since its unneeded

app.UseMvc(routes =>
{
    //Add other routes if needed
    routes.MapRoute(
       name: "ControllerRoute",
       template: "{controller:required}/{action}/{id?}",
       defaults: new { controller = "Dashboard", action = "Index" });
});

Upvotes: 2

Related Questions