0

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!

Esteban
  • 3,108
  • 3
  • 32
  • 51
  • 1
    Please post a) other routing rules prior to the "CategoryName" one, and b) an example of how you're writing the @Html.RouteLink() – McGarnagle Apr 14 '12 at 22:49
  • There are not any routing rules above "CategoryName". The RouteLink is being written as follows: `@Html.RouteLink(item.Name, "CategoryName", new { text = item.Name })` – Esteban Apr 14 '12 at 23:43

1 Answers1

0

Are you using the - sign in the failing route?

Maybe you can find more information with the Routing debugger

And maybe you can look at this question: Failing ASP.NET MVC route. Is this a bug or corner case?

Phil Haack also give an possible answer to your problem in: ASP.NET routing: Literal sub-segment between tokens, and route values with a character from the literal sub-segment

Community
  • 1
  • 1
Andrew
  • 5,395
  • 1
  • 27
  • 47
  • Based on your information I reproduced your case, the routing seems to work. Is it possible to share some more code? – Andrew Apr 18 '12 at 18:53