EntityType 'SelectListItem' has no key defined. Define the key for this EntityType.
[Table("DemoTesting")] public class DemoTesting { [Key] public int ID { get; set; } public string City { get; set; } public List<SelectListItem> lstCity { get; set; } public DemoTesting() { } public DemoTesting(List<SelectListItem> lst) { this.lstCity = lst; } }
public ActionResult DemoDropDown() { List<SelectListItem> lstmenu = new List<SelectListItem>(); var city = (from items in ContextObj.demoContextObj select items).ToList(); foreach (var item in city) { lstmenu.Add(new SelectListItem { Text = item.City.ToString(), Value = item.ID.ToString() }); } DemoTesting obj = new DemoTesting(lstmenu); return View(obj); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)