The error occurs when i tried to Submit/Post the data... could someone please help i tried every post but they are not helping me. I am new to mvc... any help will be granted he
It could be a problem between the "Gender":
[Display(Name="Gender")]
public int GenderID { get; set; }
public IEnumerable<SelectListItem> Gender { get; set; }
If I remember well, MVC attempts to map the fields automatically. Try renaming the (Name="Gender")
in (Name="GenderID")
or IEnumerable<SelectListItem> Gender
in IEnumerable<SelectListItem> GenderEnumeration
The error means that the value of Model.Gender
is null
(and as a result the DropDownListFor()
method expects that the first parameter is IEnumerable<SelectListItem>
.
In your case, when you submit the form and ModelState
is invalid, you return the view and have not assigned a value to Model.Gender
(hence it is null
and the excption is thrown.
Ensure that you re-assign the value of Model.Gender
in the POST method (just as you did in the GET method) before you return the view.