I’ve got a view that outputs a table of projects and each project has a cell where it has a dropdown list of staff members. Lets call it project leader.
It prepopulates the list and selects the current project leader. The user can then select a new one via the dropdown. There is also another dropdownlist for another value, lets call it deputy
ie:
Project # – DropDownList1 – DropDownList2
Project # – DropDownList1 – DropDownList2
(edit: see this pic for my view, project number, then leader then deputy. Dropdowns are set to current values but will be changed and submit button at bottom of page (not in pic) will be clicked)

There is also a default value of ‘needs updating’ which is set when a staff member who was a leader/deputy has left the company (their name is no longer in the list so it defaults to that).
What I want to do, is have a submit button, so the user goes through and selects new values and then hits submit. It then posts these to the server for updating.
My question is, how does this work in terms of the action method? I’ve named each dropdown list ProjectLeader#PROJECTID# and ProjectDeputy#PROJECTID# where #PROJECTID# is the number.
@Html.DropDownList(
"ProjectLeader" + item.Project.ProjectId,
new SelectList(item.AllStaff, "StaffId", "FullName",
item.Project.Leader.StaffId),
"NEEDS UPDATING!",
new { className = "Nominated" }
)
So when I submit that form, my post values are a along the lines of
ProjectLeader254=2&ProjectDeputy254=5&ProjectLeader255=6
etc
How do I handle this in my action method? Idealy I’d have an Dictionary of Project:StaffMember for both Leaders and Deputies
ie
[HttpPost]
public ActionResult UpdateNominations(IDictionary<Project, StaffMember>
projectLeaders, IDictionary<Project, StaffMember> projectDeputies)
Or possibly just dictionary of int-int for both, with the ProjectId as key and StaffId as value, as I’ll probably have to look them up in the database anyway.
edit: here is my current ViewModel
public class ProjectLeaderUpdateViewModel
{
public Project Project{ get; set; }
public bool LeaderCompleted { get;set; }
public bool DeputyCompleted{ get;set;}
public IEnumerable<StaffMember> AllStaff { get; set; }
}
I am guessing I’ll need to create a custom model binding? Can anyone give me some advice on how I should go about this?
I’d create a ViewModel in this situation to represent a single project. I’m assuming a project has a single
Leader,Deputyand anOldLeader.ViewModel:
I’m assuming that you’ve got a way to get all the staff objects. The view
Edit.aspx:Controller:
The default model binder should bind the form data to the view model for you.
Updating per comments
You can model bind a list of ViewModels quite easily to:
Form partial:
~/Shared/EditorTemplates/ProjectLeaderUpdateViewModel.ascx~/Views/Edit.aspx~/Controllers/ProjectController.csNote that this is all typed up without checking, so there might be some errors.