How can I get id as parameter from url

I want to forward the following url:

/anything/anything-v43243-anything 

How can I redirect this to a specific controller and action with that identifier as a parameter? The text "nothing" must be text with at least a few characters. The identifier must begin with the letter "v". I want this to create a friendly url

+4
source share
1 answer

You can write your own route for this and the corresponding restrictions for different parts:

 routes.MapRoute( "myroute", "anything/{x}-{id}-{y}", new { controller = "SomeController", action = "SomeAction" }, new { x = "[az]+", y = "[az]+", id = @"\d+" } ); 
+1
source

Source: https://habr.com/ru/post/1479697/


All Articles