Routing question with MVC 3 and razor
I want my route to look like this:
/Products/Image11_full.jpg
My Razor looks like this:
<a rel="pgroup" title="@image.Name" href="@Url.RouteUrl("Image", new { controller = "Products", action = "Image", imageId = image.ImageId, size = "full" })" >
My route looks like this:
routes.MapRoute(
"Image",
"Products/Image{imageId}_{size}.jpg", // URL pattern, e.g. ~/Products/Image/
new开发者_如何学运维 { controller = "Products", action = "Image" }, // Defaults will also match "GetSmallImage"
new { imageId = @"\d+", size = @"\(full\|small\|medium\)" }
);
I ether don't get anything (when I use a route name) or I get a route that look like this /Products/Image?imageId=11&size=full which means it didn't find my route.
Anyone see what I'm doing wrong?
Thanks Irv
Your size constraint is not correct. Define it like this:
routes.MapRoute(
"Image",
"Products/Image{imageId}_{size}.jpg", // URL pattern, e.g. ~/Products/Image/
new { controller = "Products", action = "Image" }, // Defaults will also match "GetSmallImage"
new { imageId = @"\d+", size = @"full|small|medium" }
);
Remove controller
and action
from the RouteUrl
call. (Since they aren't in the URL parameters)
精彩评论