我希望我的路线看起来像这样:
/Products/Image11_full.jpg
我的剃刀看起来像这样:
<a rel="pgroup" title="@image.Name" href="@Url.RouteUrl("Image", new { controller = "Products", action = "Image", imageId = image.ImageId, size = "full" })" >
我的路线如下:
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\)" }
);
我没有得到任何东西(当我使用路线名称时)或者我得到的路线看起来像这样 / Products / Image?imageId = 11&amp; size = full,这意味着它找不到我的路线。
任何人都能看到我做错了什么?
由于 欧文
答案 0 :(得分:1)
您的尺码限制不正确。像这样定义:
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" }
);
答案 1 :(得分:0)
从controller
电话中移除action
和RouteUrl
。 (因为它们不在URL参数中)