html dropdownlist to controller

Why don’t you try with ViewModel, and SelectListItem? I would do something like this

Controller:

Model.Employees = employeesList.Select(employee => new SelectListItem
{
    Text = employee.FullName,
    Value = employee.Id
}).ToList();

HTML:

@Html.DropDownListFor(m => m.EmployeeId, new SelectList(Model.Employees, "value", "text"))

EmployeeId should be string. And then you just need to set EmployeeId.

Leave a Comment