Posted on: 10/22/2013 9:36:32 AM | Views : 273

I have a dropdownlistfor in mvc and i want to fill dropdownlist i write code here which i used but these code will accur error Please help me.
Repository:
public List<SelectListItem> lst = new List<SelectListItem>();
public IEnumerable<SelectListItem> GetDropDown(MvcDemoDBEntities db) { var ddl = (from h in db.Registrations select new { h.StudentName, h.ID }).ToList();
if (ddl.ToList().Count > 0) { lst.Add(new SelectListItem() { Text = "--Select--", Value = "" }); foreach (var item in ddl) { lst.Add(new SelectListItem() { Text = Convert.ToString(item.StudentName), Value = Convert.ToString(item.ID) }); } }
return lst; }
Controller:
public ActionResult Index() { MvcDemoDBEntities db = new MvcDemoDBEntities(); ViewData["Country"] = _Reg.GetDropDown(db); return View(); }
...

Go to the complete details ...