axk
axk

Reputation: 5394

ASP.NET MVC 3 binding making sure form values take priority

With a POST request in case it has the same parameter in the query string and in the body of the request which one takes priority with model binding?

Upvotes: 5

Views: 850

Answers (1)

Jason Evans
Jason Evans

Reputation: 29186

From this article, in the "Value Provders" section.

  1. Previously bound action parameters, when the action is a child action
  2. Form fields (Request.Form)
  3. The property values in the JSON Request body (Request.InputStream), but only when the request is an AJAX request
  4. Route data (RouteData.Values)
  5. Querystring parameters (Request.QueryString)
  6. Posted files (Request.Files)

So if the same name appears in multiple places, the last place the model binder looks will take precedence (I think), in your case, the querystring.

Easiest thing to do is try it. Enter a url with a &id=23" and make sure you have a HTML input field named "id" and POST that back to the controller and see which one is passed.

Upvotes: 7

Related Questions