Joe Audette
Joe Audette

Reputation: 36706

Default route action not working after upgrade to ASP.NET Core MVC 2.2

After updating my app from asp.net core 2.1 to 2.2 it seems that default route action is not working for controllers that live in a separate class library.

For example I have a default route like this:

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

and in my class library I have a controller SiteAdminController which has an Index action method.

When I visit the url /siteadmin I get the HomeController index and not the index action of the SiteAdminController

if I use /siteadmin/index then it works

How can I make it work without requiring the index action to be explicitly in the url? It worked fine in 2.1

Upvotes: 5

Views: 959

Answers (1)

Bas de Raad
Bas de Raad

Reputation: 616

Have you tried setting the defaults in the template?

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

This worked for me in Core 2.2

Upvotes: -1

Related Questions