Okay, I did my homework and search SO, and indeed I found similar questions but not reporting the behavior I'm getting.
Here is the deal, I have defined a route:
routes.MapRoute("CategoryName", "Category/Name/{text}",
new { controller = "Category", action = "Name", text = "" });
The twist here is the following:
This url: http://www.url.com/Category/Name/existingCategoryName
And this url: http://www.url.com/Category/Name/anotherExistingCategoryName
Both url's should go to the same controller method which is public ActionResult Name(string text)
but sadly the first url is going to the default Index
method, the second is being routed correctly.
I wonder why this happens, as I've been with .net mvc for several years and never experienced this behavior.
As a side note here are some facts:
- As it's being route to different methods, I doubt the code inside them has something to do with it.
- When manually write the category to something it doesn't exists in the DB as a category name it goes through the
Name
method. - The routes are placed correctly, as I'm aware the first route that matches the pattern will win.
- Even I tried place the
CategoryName
route first, the behavior is the same. - When writing each link in the
Category/Index
I use the same@Html.RouteLink()
helper, so all the links are formatted the same way.
Thanks in advance!