I really dont understand why this isn't selecting the dropdownlist value.
Iam setting the correct 'value' and 'text' that are displayed in the list of ddl items and also saying selected=true.
if (model.EmployeeID != null)
{
if(Int32.TryParse(model.EmployeeID.ToString(), out int empID))
{
var employee = context.Employee_Main.Where(e => e.EmployeeID == empID).FirstOrDefault();
if(employee != null)
{
vm.Employee = new SelectListItem() { Value = employee.EmployeeID.ToString(), Text = employee.EFullName, Selected=true };
}
}
@Html.DropDownListFor(e => e.ServiceVM.Employee, Model.Employees, "Select Employee", new { @class = "form-control" })
I got it working. I forgot to change my javascript to match with the changing model fields.
var employ = modalA.find(body).find("#ServiceVM_Employee");
employ.val(jsonObject.employeeid);