How to remove duplicate records from dropdown list this is working fine for me but I am getting records more than two because I have same names in my database but I want to remove duplicate records.
public ActionResult Index()
{
List<OrbatTable> CountryList = db.OrbatTables.ToList();
ViewBag.CountryList = new SelectList(CountryList, "CityName", "CityName");
return View();
}
public JsonResult GetStateList(String CityName)
{
db.Configuration.ProxyCreationEnabled = false;
List<OrbatTable> StateList = db.OrbatTables.Where(x => x.CityName == CityName)
.Distinct().ToList();
return Json(StateList, JsonRequestBehavior.AllowGet);
}
and this is my code for drop down list
@if (ViewBag.CountryList != null)
{
@Html.DropDownListFor(model => model.CityName, ViewBag.CountryList as SelectList,
"--Select City", new { @class = "form-control" })
}