public ActionResult JobDutyAndEmployees(int? id)
{
// Attempt to fetch the matching object
var o = m.JobDutyGetByIdWithDetail(id.GetValueOrDefault());
if (o == null)
{
return HttpNotFound();
}
else
{
// Create a form, based on the fetched matching object
var form = AutoMapper.Mapper.Map<JobDutyEditEmployeesForm>(o);
// For the multi select list, configure the "selected" items
// Notice the use of the Select() method,
// which allows us to select/return/use only some properties from the source
var selectedValues = o.Employees.Select(e => e.Id);
// For clarity, use the named parameter feature of C#
form.EmployeeList = new MultiSelectList
(items: m.EmployeeGetAll(),
dataValueField: "Id",
dataTextField: "Name",
selectedValues: selectedValues);
return View(form);
}
}