我的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
有没有人已经创建了这样的链接,可以给我一些建议吗? 提前谢谢。
答案 0 :(得分:2)
试试这个:
@Html.RouteLink("Add Image", "singleCreate", new { controller = "GalleryImage", action = "Create", id = Model.Id })