Reputation: 844
I have an action with no params. I have a form in a view which does a GET to this action. In the action I instaniate an object (so I can get some defaults from DB) and then I use UpdateModel() on it which uses the DefaultModelBinder.
So my model has the following property def:
public string[] AI { get; set; }
My querystring amongst other things from the form contains:
?AI=12-345&AI=45-43&AI=48-546
After the action calls UpdateModel() the AI property is null! HOWEVER if I change the action definition to:
MyAction(string[] AI)
Then the AI param is populated as I would have expect the models property to be. Is this a bug in the default model binder? I tried making the property List<string>
but that didn't work either.
Any ideas?
Upvotes: 2
Views: 1151
Reputation: 844
The biggest Homer DOH of my life. What I was doing was fine and MVC would have bound it just fine if it was using the DefaultModelBinder as I claimed in my post; HOWEVER adding in extra values to the model that needed binding also failed to bind (simple bool?) I dug deeper and found out that a custom binder had been registered with MVC for the type of the model and it was doing stuff for each property on the model and consequently doing nothing for my new ones, :(.
So the moral of this story is don't forget to check for binder registrations, or just don't use registration and always state explicitly.
Upvotes: 1