0

次のルートを指定しています-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") });

すべてがアクションに正しく着信するようにルーティングされますが、Url.ActionLinkのURL生成は(HTTP GETメソッドに制約されているルートを使用して)期待どおりに機能せず、代わりにPOST / PUT/DELETEに制約されているルートを見つけます。間違ったURL。ルートを並べ替えてみましたが、役に立ちません。URL生成は制約を無視することを期待しています。

独自のActionLinkメソッドを作成する以外に、回避策はありますか?

編集

リストの下部にはデフォルトルートもあります。

routes.MapRoute("Default", "{controller}/{action}", new { controller = "home", action = "index" });
4

1 に答える 1

1

問題は解決しました - 問題は、作成アクションへのリンク (つまり、GET の場合) で機能しないということでした。制約)。機能するルートのリスト(デフォルトのものを含む)は次のとおりです。

routes.MapRoute("Retrieve/UpdateSetup/DeleteSetup", "{controller}/{id}/{action}", new { action = "retrieve" }, new { action = "retrieve|update|delete", httpMethod = new MyHttpMethodConstraint("GET", "HEAD"), id = new GuidRouteConstraint() });
routes.MapRoute("CreateSetup", "{controller}/create", new { action = "create" }, new { action = "create", httpMethod = new MyHttpMethodConstraint("GET", "HEAD") });
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 = "delete" }, new { action = "delete", httpMethod = new MyHttpMethodConstraint("DELETE"), id = new GuidRouteConstraint() });
routes.MapRoute("Create", "{controller}", new { action = "create" }, new { action = "create", httpMethod = new MyHttpMethodConstraint("POST") });

routes.MapRoute("Default", "{controller}/{action}", new { controller = "home", action = "index" });
于 2012-04-13T19:23:38.160 に答える