Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:29:36+00:00 2026-05-27T05:29:36+00:00

I’ve got a view that outputs a table of projects and each project has

  • 0

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)
mvc view

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:29:36+00:00Added an answer on May 27, 2026 at 5:29 am

    I’d create a ViewModel in this situation to represent a single project. I’m assuming a project has a single Leader, Deputy and an OldLeader.

    ViewModel:

    public class Project {
        public int Leader { get; set; }
        public int Deputy { get; set; }
        public int OldLeader { get; set; }
    
        // Add more properties as required.
    }
    

    I’m assuming that you’ve got a way to get all the staff objects. The view Edit.aspx:

    <% using (Html.BeginForm()) { %>
        <%= Html.DropDownListFor(p => p.Leader, new SelectList(StaffRepository.AllStaff, "StaffId", "FullName")) %>
        <%= Html.DropDownListFor(p => p.Deputy, new SelectList(StaffRepository.AllStaff, "StaffId", "FullName")) %>
        <%= Html.DropDownListFor(p => p.OldLeader, new SelectList(StaffRepository.AllStaff, "StaffId", "FullName"), "Needs updating!") %>
    <% } %>
    

    Controller:

    public ActionResult Edit(int id) {
        // Get the project you're editing. Do this with whatever method you're already using - EF4, NHibernate etc.
        Project p = ProjectRepository.GetById(id);
        return View(p);
    }
    
    [HttpPost]
    public ActionResult Edit(Project p) {
        // p should have it's properties bound by the default model binder.
    }
    

    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

    <%@ Control Inherits="ViewUserControl<ProjectLeaderUpdateViewModel>" %>
    <%= Html.HiddenFor(p => p.Project.ProjectId) %>
    <%= Html.DropDownListFor(p => p.Project.Leader.StaffId, new SelectList(p.AllStaff, "StaffId", "FullName")) %>
    <%= Html.DropDownListFor(p => p.Project.Deputy.StaffId, new SelectList(p.AllStaff, "StaffId", "FullName")) %>
    <%= Html.DropDownListFor(p => p.Project.OldLeader.StaffId, new SelectList(p.AllStaff, "StaffId", "FullName"), "Needs updating!") %>
    

    ~/Views/Edit.aspx

    <%@ Page Inherits="ViewPage<IList<ProjectLeaderUpdateViewModel>>" %>
    
    <% using (Html.BeginForm()) { %>
        <% for (int i = 0; i < Model.Data.Count; i++) { %>
            <%= Html.EditorFor(p => p[i]) %>
        <% } %>
    <% } %>
    

    ~/Controllers/ProjectController.cs

    public ActionResult Edit() {
        var projects = ProjectRepository.All();
        return View(projects);
    }
    
    [HttpPost]
    public ActionResult Edit(ICollection<ProjectLeaderUpdateViewModel>) {
        // Hopefully, collection will contain all the bound view model objects.
    }
    

    Note that this is all typed up without checking, so there might be some errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.