Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC URL generation for links choosing wrong route with HTTP method constraints
    text
    copied!<p>I have the following routes specified - MyHttpMethodConstraint is one that checks the HTTP Method overriden by form a variable.</p> <pre><code>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") }); </code></pre> <p>Everthing is routed correctly incoming to the Actions, however URL generation for Url.ActionLink's do not work as I hoped (using the routes that are constrained to HTTP GET methods) but instead finding the ones that are constrained to POST/PUT/DELETE and thus the wrong URLs. I have tried re-ordering the routes but this does not help. I expect that that URL-generation ignores the constraints.</p> <p>Is there a workaround, apart from building my own ActionLink method? </p> <p><strong>EDIT</strong></p> <p>There is also a default route at the bottom of the list:</p> <pre><code>routes.MapRoute("Default", "{controller}/{action}", new { controller = "home", action = "index" }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload