0

I have an action in a controller with the following route defined.

[Route(@"mycontroller/myaction/{itemId:int}-{itemSlug}"]
public ActionResult MyAction(int itemId, string itemSlug) {
  ...
}

It works and hits the action with proper parameters if the itemSlug itself does not contain a dash, but if it does, the route doesn't get hit. I don't udnerstand it, because in my opinion the correct behaviour would be to leave the rest of the dashes and process them as part of itemSlug if I constrain the part before the first dash to be integer.

How to overcome this issue? I would'nt like to use a different character to separate itemId and itemSlug.

Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93

1 Answers1

0

This may help, answer taken from here


While you could try these settings in config file

<system.web>
     <httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
     <pages validateRequest="false" />
</system.web>

I would avoid using characters like '&' in URL path replacing them with underscores.


Community
  • 1
  • 1
  • Thanks, but I'm aware of using such special characters. I was talking about simple dashes, which AFAIK completely valid URI characters. My problem is rather related to route parsing I guess. – Zoltán Tamási Aug 04 '14 at 11:18