2012-04-13 4 views
0

次のルートが指定されています - MyHttpMethodConstraintは、フォームによって変数のオーバーライドをチェックするものです。HTTPメソッド制約で間違ったルートを選択するリンクのASP.NET MVC URL生成

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は私が代わりに拘束されているものを見つける(HTTP GETメソッドに拘束されたルートを使用して)期待して動作しませんUrl.ActionLinkのためしかし、URLの生成、アクションに正しく入ってくるルーティングされますPOST/PUT/DELETE、したがって間違ったURLが含まれます。私は経路の再注文を試みましたが、これは助けになりません。私はそのURL生成が制約を無視することを期待しています。

私自身のActionLinkメソッドを構築する以外に、回避策はありますか?

EDIT

は、リストの一番下に、デフォルトルートでもあります:解決

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

MyHttpMethodConstraintのコードを提供できますか? HttpMethodConstraintは何もしないのですか? – danludwig

+0

あなたの答えに私のコメントを見てください - 標準のHttpMethodConstraintはX-HTTP-Method-Overrideを処理しません –

答えて

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" }); 
関連する問題