Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4MVC - different controllers conflict

I have actions

public virtual ActionResult Show(string userId)

and

public virtual ActionResult Show(int groupId)

In Global.asax I have

routes.MapRoute(
                "Group_Default",
                "{controller}/{action}/{groupId}",
                MVC.Groups.Show()
            );

            routes.MapRoute(
                "UserProfile_Default",
                "{controller}/{action}/{userId}",
                MVC.Profile.Show()
            );

Now when I request for group/show/... it works fine. But when I call Profile/Show/... parameter is null. But if I remove UserProfile_Default then both works but profile URL contains question mark for parameter (and I want it clean like .../profile/show/5678)
It seams that somehow one route block another.

like image 489
1110 Avatar asked Dec 12 '25 15:12

1110


1 Answers

Try these instead:

routes.MapRoute(
    "Group_Default",
    "Group/{action}/{groupId}",
    new { controller = "Group" }
);

routes.MapRoute(
    "UserProfile_Default",
    "Profile/{action}/{userId}",
    new { controller = "Profile" }
);

For future reference, the route debugger is a really good tool to see exactly what's going on with your routing and which URLs are hitting what actions: http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

like image 114
mattytommo Avatar answered Dec 15 '25 04:12

mattytommo