Reputation: 305
OK, I've been looking through a representative sample of the MVC 3 routing questions/answers, and I answered 80% of my question. A good thing, but now the most difficult part remains unsolved.
In my world, I have a URL localhost/Location/Guid
Works great, based off of this route that I've entered before my default route:
routes.MapRoute(
"Location",
"Location/{id}",
new { controller = "Location", action = "Details", id = System.Guid.Empty }
);
I can pass in the Guid for the location I want displayed, but that's down-right FUGLY. I'd really like to see the URL displayed in the address bar, and linked within a page as: localhost/Location/Paris
Obviously, I could change the parameter to a string and pass in "Paris", but I don't understand how to get the database to understand that I want Paris, France and not Paris, Texas without the use of the Guid.
I really need some help on this one, not just to solve my immediate problem, but also to better understand routing in general. I thought I had a handle on it sufficient for my needs, but obviously, I don't.
Thanks in advance!
Upvotes: 0
Views: 95
Reputation: 4619
You're going to have to put something in the URL to disambiguate between Paris, France, and Paris, TX.
/Location/{locationSlug}
. If you have multiple locations named "Paris", you slugify them and append an auto-incrementing # to the end (e.g., /Location/paris, /Location/paris-1, /Location/paris-2). Or you can add region/city/country info to the slug to disambiguate, instead of the #. Location/{id}/{locationSlug}
(e.g., /Location/1245/paris). Upvotes: 2