MVC ActionLink generating NON-Restul URL AFTER adding constraints
Posted
by brianstewey
on Stack Overflow
See other posts from Stack Overflow
or by brianstewey
Published on 2010-04-16T09:01:45Z
Indexed on
2010/04/16
9:03 UTC
Read the original article
Hit count: 461
Hello
I have a custom route that without constraints generates a Restful URL with an ActionLink. Route -
routes.MapRoute(
"Blog", // Route name
"Blog/{d}/{m}/{y}", // URL with parameters,
new { controller = "Blog", action = "Retrieve" }
Generates -
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 constraints like so.
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
Extra information: it is added before the custom route.
Any ideas? Cheers
© Stack Overflow or respective owner