I’ve had an issue which has consumed the majority of today: my MVC action, “Save”, with 1 parameter has been receiving an empty object as its parameter despite the form posting what looked like valid data. It seemed like the model binder was refusing to bind the posted data for some reason.
The situation was thus:
- Form posting multiple properties of the
ObjectBatchobject in the format
Saveaction accepting a single parameter,
Well, after a day of fiddling (and nearly jumping out the window a few times), I eventually discovered that the object was correctly creating the
ObjectBatch until adding the
Finally, my colleague @Benjimawoo suggested adding a second parameter for the sub-collection and adding them to the main object within the action.
Then it dawned on me… MVC matches the parameter names to the name format of the posted fields. This meant that, after populating the
ObjectBatch, it was recreating it using the
Simply renaming the parameter from
ObjectBatch objects to
ObjectBatch batch solved this!
I see exactly why its done like that… still a bit of a pain though!