2011-02-02 157 views
0

路由的問題,我想我的路線是這樣的:與MVC 3和剃刀

/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 & size = full這意味着它沒有找到我的路線。

有人看到我在做什麼錯了嗎?

感謝 歐文

回答

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" } 
      ); 
+0

是的,這確實起作用。我實際上通過完全去除大小約束來實現它。 – 2011-02-02 19:15:54

0

RouteUrl通話中移除controlleraction。 (因爲它們不在URL參數中)