Map Routes works only default

Asked

Viewed 91 times

0

I’m having a problem with my project. I have two routes, a "Default" and a test, but I do not know if it is done correctly because it does not work when they put in the url what I put there, works only the "Default"

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "TestRoute",
            "{id}",
            new { controller = "Inicio", action = "Inicio", id = UrlParameter.Optional },
            new { id = @"\d+" } //one or more digits only, no alphabetical characters
        );
        //default route
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Inicio", action = "Inicio", id = UrlParameter.Optional }
        );
    }

1 answer

1


Your two routes are pointing to the same Controller and Action.

See the following route mapping model I found in this question here

   context.MapRoute(
                "Comment_default",
                "Comment/PostMsg",
                new { controller = "Comment", action = "PostMsg", id = UrlParameter.Optional },
                new[] { "Demo.Web.Controllers" }
            );

            context.MapRoute(
                "Comment_default",
                "Comment/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                new[] { "Demo.Web.Areas.Comment.Controllers" }
            ); 
  • Any type of route I create (even if the default is removed) only works the page when I call {controller}/{action}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.