문제

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?

도움이 되었습니까?

해결책

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}"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top