asp.net mvc - String parameter not being populated using URL routing -


url rewriting issue. when call me url using following link

http://localhost:12719/product/18 

it works fine product 18 links parameter. when call using following.

http://localhost:12719/product/apple 

it doesn't map apple product name controller, thinking trying invoke action of type apple.

why map numeric , not string controller parameter? controller parameter type of string.

routing below.

routes.maproute(     name: "product",     url: "product/{id}/{slug}",     defaults: new { controller = "product", action = "product", slug = urlparameter.optional },     constraints: new { id = @"\d+" } ); 

you have specified id numeric in regex specified in constraint. constraints: new { id = @"\d+" } remove , should work. since "product" doesnot pass \d+ test id null in action.

routes.maproute(     name: "product",     url: "product/{id}/{slug}",     defaults: new { controller = "product", action = "product", slug = urlparameter.optional }  ); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -