-1

我的 mvc4 项目中有以下路由配置:

routes.MapRoute(
            name: "single",
            url: "{controller}/{id}",
            defaults: new { controller = "Home", action = "Details" },
            constraints: new { id = @"^[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}$" }
        );

        routes.MapRoute(
            name: "singleCreate",
            url: "{controller}/{id}/{action}",
            defaults: new { controller = "GalleryImage", action = "Create" },
            constraints: new { id = @"^[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}$" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

现在我想创建一个指向“singleCreate”路线的链接。

我试过这个:

@Html.ActionLink("Add Image", "Create", "GalleryImage", new { id = Model.Id }, null)

但这并不像我预期的那样工作。我得到一个没有动作的链接,如下所示:

/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4

链接应该是这样的:

/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4/Create

有没有人已经创建了这样的链接并且可以给我一些建议?提前致谢。

4

1 回答 1

2

尝试这个:

@Html.RouteLink("Add Image", "singleCreate", new { controller = "GalleryImage", action = "Create", id = Model.Id })
于 2013-08-20T14:57:28.227 回答