How Do I get City State Zip in MVC 3 URL Route without writing a controller for every state and actions for each city

Posted by OpTech Marketing on Stack Overflow See other posts from Stack Overflow or by OpTech Marketing
Published on 2012-05-30T22:38:48Z Indexed on 2012/05/30 22:40 UTC
Read the original article Hit count: 219

Filed under:
|
|

I have the need to have the urls in my bosses application look like:

http://domain.com/Texas/Dallas/72701

However, I don't want to write a controller for every state and an action for every city.

routes.MapRoute(
"DrillDown", // Route name
"{controller}/{action}/{ZipId}", 
new { controller = "State", action = "City", ZipId = UrlParameter.Optional} // Parameter     defaults

Can someone help me write a pattern for the routes that will accept State/City/Zip without destroying the ability for me to have regular routes with controller/Action/Param ?

Looking all over and can't find any direction.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-3

Related posts about routes