I always getting this error in my dropdownlistfor:
Value cannot be null.
Parameter name: items
View code:
@Html.DropDownListFor(model => model.SiteId, new SelectList(ViewBag.ListSiteClass, "SiteId", "SiteName"), "", new { @onchange = "GetSiteid(this.value);" })
Controller Code:
[HttpPost]
public ActionResult Create(ServiceDTO ms, FormCollection form)
{
if (ModelState.IsValid)
{
int sid = ms.SiteId;
ServiceDAO.Insert(sid);
}
else
{
return View();
}
}
In loading View:
public ActionResult Create()
{
List<SiteDTO> LSSiteNameList = SiteDAO.GetSiteNameList(User.Identity.Name);
ViewBag.ListSiteClass = LSSiteNameList;
var service = new ServiceDTO();
return View(service);
}