Pergunta

Here is my code:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
            );

            routes.MapRoute(
                "Admin", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Admin", action = "Index", id = UrlParameter.Optional } 
            );  
        }

for first link it works well if i go to: localhost/song localhost/date etc. it opens all links under home controller.

But for second maproute: localhost/admin localhost/admin/index - these link are not working? Can anyone please tell me what i am doing wrong?

Foi útil?

Solução

First, your default route must be last in the list, not first.

Second, You have two default routes. There is no way for MVC to know which one to use, so it always chooses the first one that matches. Instead, your Url for the admin one should be "Admin/{action}/{id}"

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top