Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 635
axk Avatar asked Jul 18 '13 12:07

axk


1 Answers

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.

like image 130
Jason Evans Avatar answered Sep 20 '22 14:09

Jason Evans