1

我有这条路

在视图中

  <img src="PhotoDisplay.ashx?photoid=12&size=medium" alt="Image with no resize"/>

我想将源 url 路由到一个 action 。我必须使用这种 url 格式,因为我正在重建一个站点。所以我也想让所有链接在新站点中保持活跃。在 global.asax 我添加了如下所示的溃败

routes.MapRoute(
          "PhotoDisplay", "PhotoDisplay.ashx?photoid={photoID}&size={size}",
          new { controller = "Images", action = "PhotoDisplay", photoid= "",size="" }
      );

但它在编译时给出错误。我怎样才能映射那种 url 的路由

4

1 回答 1

1

查询字符串参数不应在路由中定义。试试这样:

routes.MapRoute(
    "PhotoDisplay", 
    "PhotoDisplay.ashx",
    new { controller = "Images", action = "PhotoDisplay" }
);

和控制器动作:

public ActionResult PhotoDisplay(string photoid, string size)
{
    ...
}
于 2011-10-22T18:02:00.077 回答