1

In my config file I've set the url rule like this :

<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>

And what happens is:-

controller/action/123 (work)
controller/action/hello (not work)

But it accepts only digit as the parameter.
What I want is that both digit and string should be accepted.

Please help!!!!

Dharmesh Porwal
  • 1,406
  • 2
  • 12
  • 21
Chhorn Soro
  • 3,061
  • 8
  • 27
  • 43
  • Do you meant the entire string after 123? You need to encode the string because the ' ' (spaces) will cause isses. http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode%28v=vs.110%29.aspx – Murray Foxcroft Jan 09 '15 at 08:34
  • I mean that If action parameter is the string it's not working. – Chhorn Soro Jan 09 '15 at 08:37

1 Answers1

2

The d+ pattern matches numbers 0-9, so it is working as expected. Change the regex pattern to match strings. Try w+.

Change:

<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>

To:

<controller:\w+>/<action:\w+>/<id:\w+>' => '<controller>/<action>
Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86