[RESOLVED]MVC – adding dynamic controls to each row in list

I have a dynamically created table with employee data (name/emp number/start date/title). We’re trying to keep track of the percent of an employee’s job doing certain duties.

What I need (for each employee) is to add a dropdown list with a list of duties, and then add a a textbox for percentage of time (don’t worry about percentage), but I need 4 of each per employee, named with some relevance to each employee

Like:

Emp Name-Emp Number – DropDownList – TextBox                                       

                                            DropDownList – TextBox                                       

                                            DropDownList – TextBox                                       

                                           DropDownList – TextBox

Each Dropdownlist will have the same items in it, and the end user will select from the DDL, and enter the number in the textbox.

I’ve tried this:

 for (int lines = 1; lines < 5; lines++)
    {
<tr>
    <td colspan="5">&nbsp;</td>
    <td class="altText">radio buttons</td>
    <td class="altText">ddlActivity + @item.empNumber + @lines.ToString()</td>
    <td class="altText">DropDown</td>
    <td class="altText">FTE Textbox</td>
    <td class="altText">Total FTETTextbox</td>
</tr>
    } 

But the output is more like the formula and not what I need: ddlActivity + (empNumber is correct) + 1 with the plus shines showing.

How can I create name these dynamic controls (and populate the dropdownlists) so that they’re tied to that particular employee?

elmoWatson

How can I create name these dynamic controls (and populate the dropdownlists) so that they’re tied to that particular employee?

Put the names as in the property – see http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

Also, it maybe worth to study MVVM in javascript http://msprogrammer.serviciipeweb.ro/2014/01/05/javascript-mvvm-and-asp-net-mvc/

Leave a Reply