I have a dropdown list that is populating correctly on the page load but when I select a choice and submit it back with data from additional fields I am getting this error. Do I need to reset it back to the default value? In the below code "Industries" is a List of type SelectListItem.
@using (Html.BeginForm())
{
@Html.DropDownListFor(n => n.SelectedItem, Model.Industries)
<br>
//MORE CONTROLS
<br>
<input type="submit" value="Calculate" />
}
[HttpGet]
public ActionResult Calculate()
{
ClassName DataStuff = new ClassName ();
return View(new ClassName { Industries = DataStuff.IndustryList()
});
}
[HttpPost]
public ActionResult Calculate(ClassName Items)
{
ClassName CompleteItems = RetrieveData(Items);
// above additional calculations
return View(CompleteItems);
}
The model (with the relevant fields) is:
public class ClassName
{
public string SelectedItem { get; set; }
public IEnumerable<SelectListItem> Industries { get; set; }
public List<SelectListItem> IndustryList()
{
//populating the DDL
}
}