provide URL without the unique parameter names

Go To


Does anyone know how to provide routing maps for multiple controllers in the same area with multiple parameter names?

I have a request to provide URL without the parameter names (only values) for each controller with unique parameter names (to avoid ambiguity)

Is this possible?

I would like to get this output in URL:


using something like this:

                new { controller = "mycontrollerName1", action = "Index", customID= UrlParameter.Optional, sustomID2= UrlParameter.Optional },
                new string[] { "Project.Areas.SomeArea.Controllers" }

                new { controller = "mycontrollerName2", action = "Index", customValue= UrlParameter.Optional, sustomID3= UrlParameter.Optional },
                new string[] { "Project.Areas.SomeArea.Controllers" }
2012-04-04 21:14
by matendie


You need to use RegEx routes (I used an article on this to guide me on how to create it once... worked great). I have used them in the past for this type of thing. I would suggest you dont do this as it could lead to bugs. What if you add regex rules to catch based on all numbers and it uses the other route if the parm has non-numeric values... then a user enters all numeric in that place?? I think it will lead to hard to find bugs.

Want something better? Does the business insist you use those URLs? You could also consider using URL rewrite rules to write it to another route outside of the MVC framework, then change the routes to be more unique.

2012-04-04 21:22
by CrazyDart
Instead of just saying this is a really bad idea why not include why you think it's a bad idea? Much more useful that way : - Shane Courtrille 2012-04-04 21:28
Shane Courtrille, I did just that... good thinking - CrazyDart 2012-04-04 21:31
Thanks for your reply. I will look in to the URL rewriting, that may turn out to be better solution - matendie 2012-04-05 13:40