开发者

MVC3 Validation Issue NullReference Exception

When I click the submit button on my form, I get a null reference exception error during the reload following the submit event, that is generated by my dropdownlist. The data loads fine during initial l开发者_C百科oad. It is my understanding that the data is maintained by convention and should be retained. I also looked at the modelstate and the error for the required field was raised and the error message exists inside the ModelState object.

But, it looks like this convention is not working for this dropdown. So, this line below raises the error: @Html.DropDownListFor(m => m.Company.DeptId, Model.DeptList)

What am I doing wrong?


The value for the posted model property (DeptId) is retained, but the contents of the property DeptList are not since they were not posted back. Only the properties on the model that correspond to form elements that are posted can be reconstituted on the model. On error you'll need to repopulate any properties of the model that don't correspond to inputs in the view so that the view renders properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜