I was taking advantage of model binding to populate a particular parameter name in 3 separate places within an action method signature (2 filter entity parameters and a normal controller action parameter).
i.e.
public ViewResult foo(Entity1 something, Entity2 somethingelse, somefield)
where Entity1 and Entity2 both have somefield within them.
For one request I tested using GET and everything worked fine. For another request I used POST and only the parameter by the exact same name in the action method was populated. The rest of the parameters in the entities were mapped correctly. I tested it with another parameter, and found the same results.
Does ASP.NET MVC only populate one parameter by a particular name for POST requests, but multiple instances of a parameter by a particular parameter name for GET requests? Is this “undefined” behavior and a misuse of the model binder?
I am quite sure something else is amiss. I just gave it a test with the following
and as controller method:
and for the view just a simple
and it works as expected, both
bar.Name,foo.Name, andNameitself are filled with the value supplied when submitting.So no difference between POST and GET.
To even go further into detail, this is what MVC does, where MethodInfo is an object of type
System.Reflection.MethodInfo, which represents the action method about to be executed:So for each parameter defined for the given method it will try to retrieve the parameter values from object
parameterswhich is, amongst others, what is supplied by the querystring.