ASP.Net MVC - model with collection not populating on postback

后端 未结 6 477
面向向阳花
面向向阳花 2020-12-01 19:08

I have an ASP.Net MVC application with a model which is several layers deep containing a collection.

I believe that the view to create the objects is all set up co

6条回答
  •  渐次进展
    2020-12-01 19:42

    If a property is null, then the model binder other could not find it or could not find values in the submitted form necessary to make an instance of the type of the property. For example, if the property has a non-nullable ID and your form does not contain any data for that ID , the model binder will leave the property as null since it cannot make a new instance of the type without knowing the ID.

    In other words, to diagnose this problem you must carefully compare the data in the submitted form (this is easy to see with Firebug or Fiddler) with the structure of the object you are expecting the model binder to populate. If any required fields are missing, or if the values are submitted in such a way that they cannot be converted to the type of a required field, then the entire object will be left null.

提交回复
热议问题