Im trying to make dropdown list in my razor view using Viewbag but its not working, Im missing something I guess
public IEnumerable<SelectListItem> GetAllEmployeeForPayroll()
{
return GetAll().Select(emp => new SelectListItem()
{
Text = emp.FullName,
Value = emp.Id.ToString()
});
}
ViewBag.employees = _employeeService.GetAllEmployeeForPayroll();
<label asp-for ="EmployeeId"></label>
<select asp-for="EmployeeId" class="form-control" asp-item="ViewBag.employees">
<option selected >---Select Employee---</option>
</select>
<span asp-validation-for ="EmployeeId" class="text-danger"> </span>
this is my code Im sure I did something wrong in razor view but cant figure out what.enter code here
2
Answers
It should be
asp-items
but notasp-item
.I hope this answer your question regards.