i am picking list of names from database, according to scenario each name exists many times in database, That's ok. Now i have filled a DROPDOWNLIST with those names but in drop down list each name appears several times but i want to display each name 1 time in DROPDOWN. I have used distict() but not working. I'm USING MVC 3, Linq to SQL.
EmployeeAtdDataContext DataContext = new EmployeeAtdDataContext();
public ActionResult ddl()
{
var names = (from n in DataContext.EmployeeAtds select n).Distinct();
ViewData["EmplID"] = new SelectList(names, "EmplID", "EmplName");
return View();
}
public ActionResult showDDL(string EmplID)
{
ViewBag.EmplID = EmplID;
return View();
}
Views:
@{
ViewBag.Title = "ddl";
}
<h2>ddl</h2>
@using (Html.BeginForm("showDDL", "Home", FormMethod.Get))
{
<fieldset>
Employers
@Html.DropDownList("EmplID", "Select Name")
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
}