I’ve got a view which is adding a bunch of data into a bound EditModel. However, when it is POSTed, for some reason a parameterless constructor is called before calling the POST Action, instead of just passing back the model that was bound to the view.
I thought all I had to do was to make sure I reference the model in the “Inherits” tag at the top of the view, but for some reason all of the filled in data just gets thrown away on POST and a new instance of the model is instantiated. The View certainly seems to be able to see the model, as I can use Visual Studio Intellisense to access the model fields.
I’m sure it is something simple I am missing, so any pointers as to where to look would help. I can paste in some code if it helps.
Thanks!
As Omu says it will always call the parameterless constructor with a default modelbinder. Basically the modelbinder populate public memberes from the form collection based on the element names (plus maybe a prefix if defined). You need to make sure your element names (not Ids) match the public members you want populating on the model.