Asp.net mvc 操作前id为的asp.net mvc操作链接
我的mvc4项目中有以下路由配置:Asp.net mvc 操作前id为的asp.net mvc操作链接,asp.net-mvc,asp.net-mvc-routing,actionlink,Asp.net Mvc,Asp.net Mvc Routing,Actionlink,我的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}[-]?){
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
链接应如下所示:
/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4
/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4/Create
有没有人已经创建了这样的链接,可以给我一些建议?
提前感谢。试试这个:
@Html.RouteLink("Add Image", "singleCreate", new { controller = "GalleryImage", action = "Create", id = Model.Id })
我试过了。现在我得到了一个指向错误控制器的链接:真正令人惊讶的是,当我为ActionLink使用不同的操作时,该操作被正确地附加在链接的末尾。我必须重新命名我的视图,但一切都正常。如果我将视图保留为原始视图,我不明白会出现什么问题。仍然没有运气:/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4