MVC ActionLink generating NON-Restul URL AFTER adding restrictions

I have a no-limit custom route that generates a Restful URL with ActionLink.

Route -

 routes.MapRoute(
          "Blog", // Route name
          "Blog/{d}/{m}/{y}", // URL with parameters,
          new { controller = "Blog", action = "Retrieve" }

Creates -

   http://localhost:2875/Blog/12/1/2010

From -

<%=Html.ActionLink("Blog Entry - 12/01/2010", "Retrieve", "Blog", new { d = 12, m = 01, y = 2010 }, null)%>

If I add such restrictions.

            routes.MapRoute(
          "Blog", // Route name
          "Blog/{d}/{m}/{y}", // URL with parameters,
          new { controller = "Blog", action = "Retrieve" },
          new { d = @"\d{2}", m = @"\d{2}", y = @"\d{4}" }

It generates -

http://localhost:2875/Blog/Retrieve?d=12&m=1&y=2010

Additional information: it is added to the user route.

Any ideas? Greetings

+3
source share
2 answers

I worked on the same issue when writing my blog. In the end, I realized that my Urls will have to use numbers in 1 bit month. change the route definition to this and it will work:

routes.MapRoute(
   "Blog", // Route name
   "Blog/{d}/{m}/{y}", // URL with parameters,
   new { controller = "Blog", action = "Retrieve" },
   new { d = @"\d{1,2}", m = @"\d{1,2}", y = @"\d{4}" }

2- /.. ​​ , ..

- pls ^ _ ^

+4

Artiom . ActionLink , . , , Artiom, ActionLink, "" ( ):

Html.ActionLink("Blog Entry - 12/01/2010", "Retrieve", "Blog", new { d = "12", m = "01", y = "2010" }, null)

+1

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


All Articles