我指定了以下路由 - MyHttpMethodConstraint 是一种检查由变量覆盖的 HTTP 方法的路由。
routes.MapRoute("Retrieve", "{controller}/{id}/{action}", new { action = "retrieve" }, new { action = "create|retrieve|update|delete", httpMethod = new MyHttpMethodConstraint("GET", "HEAD"), id = new GuidRouteConstraint() });
routes.MapRoute("Update", "{controller}/{id}", new { action = "update" }, new { action = "update", httpMethod = new MyHttpMethodConstraint("PUT"), id = new GuidRouteConstraint() });
routes.MapRoute("Delete", "{controller}/{id}", new { action = "destroy" }, new { action = "delete", httpMethod = new MyHttpMethodConstraint("DELETE"), id = new GuidRouteConstraint() });
routes.MapRoute("Create", "{controller}", new { action = "create" }, new { action = "create", httpMethod = new MyHttpMethodConstraint("POST") });
Everthing 被正确路由到 Actions,但是 Url.ActionLink 的 URL 生成并没有像我希望的那样工作(使用受限于 HTTP GET 方法的路由),而是找到那些受限于 POST/PUT/DELETE 的路由,因此错误的网址。我尝试重新排序路线,但这无济于事。我希望 URL 生成忽略约束。
除了构建我自己的 ActionLink 方法之外,是否有解决方法?
编辑
列表底部还有一条默认路由:
routes.MapRoute("Default", "{controller}/{action}", new { controller = "home", action = "index" });