问题描述:

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.

网友答案:

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.


相关阅读:
Top