Reputation: 1421
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.
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
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