Reputation: 1205
With the below code I get all the names of the employee.
How can I add a where clause to only get current employees where empStatus=1?
private void BindDropDownList()
{
var employees = dbEmployee.employeestable.Select(x => new
{
FullName = x.emp_first + " " + x.emp_last,
Id = x.empid
}).ToList();
ViewBag.Employees = new SelectList(employees, "FullName", "FullName");
}
Upvotes: 1
Views: 38
Reputation: 246998
Add a Where
filter before the Select
var employees = dbEmployee.employeestable
.Where(x => x.empStatus == 1) //<----HERE
.Select(x => new {
FullName = x.emp_first + " " + x.emp_last,
Id = x.empid
})
.ToList();
//...
Upvotes: 1