I'm using mvc3 with dynamically created forms, and the default modelBinder is not helping me.
I'd like to obtain control over the form collection keys that are associated with control values and posted back in the form collection.
controllerContext.HttpContext.Request.Form["IWantToSetThisKeyRightHere"]
Currently those keys are auto-generated someplace that I don't understand to support default model binding, which doesn't work for me anyways.
How do I set those values when creating the view so that I can experiment with my own custom model binder to extract the data when the dynamic form is posted?
Thanks
The key to the form collection comes from the name property of the input element. I was trying to override that by using an html helper and passing in a new value for the name attribute.
Like this:
The name value I was trying to set (Model.UniqueName) was being overwritten by a string that was presumably designed by mvc to allow it to map the value back to the same Model class during modelBinding after the post.
Since my system is dynamic, mvc cannot map the data back to the Model. I wanted to take control of that value to enable me to map the data back manually on post.
The solution was very simple, all I had to do was not use the @Html.TextBox helper to generate the textbox, and create it myself with my intended name property.
This permits me to hook the posted values back into my dynamically structured model on post.