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 3636466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:02:12+00:00 2026-05-19T01:02:12+00:00

So I have a custom ViewModel ( CompanySalaryDataViewModel ) that has a collection of

  • 0

So I have a custom ViewModel (CompanySalaryDataViewModel) that has a collection of other ViewModels on it (PersonalIncomeViewModel). Ultimately, I want to have an EditorTemplate for a CompanySalaryDataViewModel that consumes an EditorTemplate for a PersonalIncomeViewModel somehow in a way that it provides 2-way binding to my ViewModel when it’s passed back into my POST controller.

For example, let’s say it’s something like this:

public class CompanySalaryDataViewModel
{
    string CompanyName { get; set; }
    IList<PersonalIncomeViewModel> AllSalaryData { get; set; }
}

public class PersonalIncomeViewModel
{
    long UniqueID { get; set; }
    string PersonName { get; set; }
    int JanIncome { get; set; }
    int FebIncome { get; set; }
    int MarIncome { get; set; }
    int AprIncome { get; set; }
    int MayIncome { get; set; }
    int JunIncome { get; set; }
    int JulIncome { get; set; }
    int AugIncome { get; set; }
    int SepIncome { get; set; }
    int OctIncome { get; set; }
    int NovIncome { get; set; }
    int DecIncome { get; set; }
}

I want this done in a way where it’s similar to the following markup but works:

<%= Html.TextBoxFor(x => x.CompanyName) %>
    <table cellspacing="0">
        <thead>
            <tr class="t-grid-header">
                <th class="t-header">ID</th>
                <th class="t-header">Person</th>
                <th class="t-header">Jan</th>
                <th class="t-header">Feb</th>
                <th class="t-header">Mar</th>
                <th class="t-header">Apr</th>
                <th class="t-header">May</th>
                <th class="t-header">Jun</th>
                <th class="t-header">Jul</th>
                <th class="t-header">Aug</th>
                <th class="t-header">Sep</th>
                <th class="t-header">Oct</th>
                <th class="t-header">Nov</th>
                <th class="t-header">Dec</th>
            </tr>
        </thead>
    <%
    var isAlt = false;
    foreach (var salaryData in Model.AllSalaryData)
    {
        var salary = salaryData;
        if (isAlt)
        {%>
            <tr class="t-alt">
        <%
        }
        else
        {%>
            <tr>
        <%
        }

        isAlt = !isAlt;
        %>
                <td><%=Html.TextBoxFor(x => salary.UniqueID)%></td>
                <td><%=Html.TextBoxFor(x => salary.PersonName)%></td>
                <td><%=Html.TextBoxFor(x => salary.JanIncome, new {id = salary.PersonName + "_1", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.FebIncome, new {id = salary.PersonName + "_2", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.MarIncome, new {id = salary.PersonName + "_3", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.AprIncome, new {id = salary.PersonName + "_4", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.MayIncome, new {id = salary.PersonName + "_5", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.JunIncome, new {id = salary.PersonName + "_6", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.JulIncome, new {id = salary.PersonName + "_7", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.AugIncome, new {id = salary.PersonName + "_8", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.SepIncome, new {id = salary.PersonName + "_9", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.OctIncome, new {id = salary.PersonName + "_10", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.NovIncome, new {id = salary.PersonName + "_11", style = "width: 45px;"})%></td>
                <td><%=Html.TextBoxFor(x => salary.DecIncome, new {id = salary.PersonName + "_12", style = "width: 45px;"})%></td>
            </tr>
    <%
    }%>
    </table>

The problems with this code are:

  1. Each “January” textbox has the same name (salary.JanIncome – doesn’t include anything to differentiate it from another salary). Same problem with every month.
  2. Perhaps because of problem #1, this doesn’t bind back to the ViewModel when I post – my AllSalaryData collection is null.
  3. All of this seems VERY non-best-practice and like there should be a better way to do this.

Ultimately, I guess I need to better understand using templates with collections but the other part of it is the “logic” to properly apply the t-alt class to the appropriate table row.

NOTE #1: I set the HTML IDs this way for some javascript stuff I have interacting with these textboxes.

NOTE #2: I’m not really doing this with salary data.

  • 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-19T01:02:13+00:00Added an answer on May 19, 2026 at 1:02 am

    Okay, so I have found a function solution that’s not ideal but it works. Apparently the foreach is the problem but a for(var i=0; i < xxx.Count; i++) works because the index number gets used for generation of the name of the rendered control. Not ideal but this works perfectly.

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

Sidebar

Related Questions

My problem is hydrating a Viewmodel from a Linq2Sql object that has been returned
I have created a custom style for my WPF datagrid by overriding its control
I have recently started using the MVVM-Light toolkit and I am stuck on the
I am creating a custom control in WPF, it is the highly unoriginal example
in my WPF UI, I use RoutedCommands that I refer to in my xaml
I've been trying to figure this for a few days now, with no luck.
Is there an easy way to transform or format a string as part of
In our SL4 application built on Caliburn.Micro, we've come across a (another) memory leak.
I am little new to Command binding so this might be a trivial question
I'm not even quite sure where to start explaining this problem. I've been working

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.