I have this to populate a drop down list in an ASP.NET MVC view.
C#
ViewBag.Employees = new SelectList(
_employeeRepository.GetAll(),
"ID",
"LastName",
employeeToClientContract.EmployeeID);
CSHTML
@Html.DropDownListFor(model => model.EmployeeID, ViewBag.Employees as IEnumerable<SelectListItem>, "Please select")
NOTE: For some reason this works
ViewBag.OverridePhysicians = new SelectList(
_employeeRepository.GetAll().Where(e => e.EmployeeTypes.TypeType == 1),
"ID",
"LastName",
employeeToClientContract.OverridePhysicianID);
@Html.DropDownListFor(model => model.OverridePhysicianID, ViewBag.OverridePhysicians as IEnumerable<SelectListItem>, "Please select")
Debugging this I can see that the Selected property is set to true when it should be. But when the view is rendered, none of the options in the list is selected.
Any ideas?
UPDATE: The problem wasn't with any of the control configurations. My problem was extra spaces in my URL. All I had to do was call .Trim() to fix the problem.
$('#itemsTable').bootstrapTable({
}).on('click-row.bs.table', function (e, row, $element) {
window.location.href = "/EmployeeToClientContract/Edit?employeeId=" + row[0].toString().trim() + "&clientContractId=" + row[2].toString().trim();
});