2

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 load. 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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.