用MVC 3和razor路由问题

时间:2011-02-02 01:44:15

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing

我希望我的路线看起来像这样:

/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,这意味着它找不到我的路线。

任何人都能看到我做错了什么?

由于 欧文

2 个答案:

答案 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电话中移除actionRouteUrl。 (因为它们不在URL参数中)