0

在我看来,我正在使用

<img src="@Url.Action("Method", new { Model.Url })" ...
<img src="@Url.Action("Method", new { Model.Url })/1" ...

在那种方法中,我有参数:

public ActionResult Method(string url, int ids=0)

var book = GetBookByUrl(url);
...
switch (ids)
{
case 1:

在我的 global.asax 中,我有:

        routes.MapRoute(null,
            "{controller}/{action}/{url}/{ids}",
            new { controller = "Controller", action = "Method", url = "", ids = @"\d+" });

我的视图返回正确的 URL(附加 /1 和 /2),但我似乎无法让我的方法检索 id 的值,以便我可以在我的操作方法中操作它们以检索基于 Url 的不同结果.Action URL 在我看来是什么提供的?

ids 参数似乎始终为 0(不是路由数据),而 url 参数具有整个 url “bla-bla/2”,这是我不想要的。

请注意,虽然有很多路由资源,但我已经阅读了它们并且似乎无法让它工作 - 这也是将数据从请求路由到控制器的标准方式吗?

请举例说明如何解决,非常感谢!

4

0 回答 0