I have dropdownlists populated from my controller and passed in the view through viewbags. The binding seems okay until I submit the form and gets null value. But when I put the codes in the view itself, it works. Am I missing a cast?
a snippet of my dropdownlist for "Year":
@Html.DropDownListFor(model => model.Year, new SelectList(ViewBag.Year, "Value", "Text"), htmlAttributes: new { @class = "form-control"})
Whereas the ViewBag.Year data is from my controller that has the ff codes:\
List<SelectListItem> year = new List<SelectListItem>();
for (var i = 1990; i <= DateTime.Now.Year; i++)
{
year.Add(new SelectListItem
{
Text = i.ToString(),
Value = i.ToString(),
Selected = false
});
}
ViewBag.Year = year;
the error I get: