I cannot seem to access a multiple select list's values when posting.
The code in the view is:
<select id="instructors" name ="instructors" multiple="multiple">
@{
List<CMMS.WebUI.ViewModels.AssignedInstructor> instructors = ViewBag.Instructors;
foreach (var instructor in instructors)
{
if (instructor.HasInstructor)
{
@:<option value="@instructor.InstructorId" selected="selected">@instructor.InstructorName</option>
}
else
{
@:<option value="@instructor.InstructorId">@instructor.InstructorName</option>
}
}
}
</select>
I have tried grabbing the values in the controller via the following ways:
[HttpPost]
public ActionResult Edit(int id, FormCollection formCollection)
{
string[] selectedInstructors = formCollection["instructors"];
...
}
[HttpPost]
public ActionResult Edit(int id, string[] instructors)
{
...
}
Both ways the instructors are always null. If anyone can tell me where I am screwing this up, I would appreciate it very much.