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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:11:12+00:00 2026-06-13T18:11:12+00:00

I am working with MVC 3, Razor views and EditorFor templates. I have three

  • 0

I am working with MVC 3, Razor views and EditorFor templates.

I have three simple nested models:-

public class BillingMatrixViewModel
{
    public ICollection<BillingRateRowViewModel> BillingRateRows { get; set; }

    public BillingMatrixViewModel()
    {
        BillingRateRows = new Collection<BillingRateRowViewModel>();
    }
}

public class BillingRateRowViewModel
{
    public ICollection<BillingRate> BillingRates { get; set; }

    public BillingRateRowViewModel()
    {
        BillingRates = new Collection<BillingRate>();
    }
}

public class BillingRate
{   
  public int Id { get; set; }
  public int Rate { get; set; } 
}

The BillingMatrixViewModel has a view:-

@using System.Collections
@using WIP_Data_Migration.Models.ViewModels
@model WIP_Data_Migration.Models.ViewModels.BillingMatrixViewModel

<table class="matrix" id="matrix">      
    <tbody>
        <tr>
           @Html.EditorFor(model => Model.BillingRateRows, "BillingRateRow")    
        </tr>
    </tbody>
</table>

The BillingRateRow has an Editor Template called BillingRateRow:-

@using System.Collections
@model IEnumerable<WIP_Data_Migration.Models.ViewModels.BillingRateRowViewModel> 

@foreach (var item in Model)
{
    <tr>
        <td>
    @item.BillingRates.First().LabourClass.Name
    </td>
    @Html.EditorFor(m => item.BillingRates)
</tr>
}

The BillingRate has an Editor Template:-

@model WIP_Data_Migration.Models.BillingRate

<td>
  @Html.TextBoxFor(model => model.Rate,
                new {style = "width: 20px"})
</td>

The markup produced for each input is:-

<input name="BillingMatrix.BillingRateRows.item.BillingRates[0].Rate"    id="BillingMatrix_BillingRateRows_item_BillingRates_0__Rate" style="width: 20px;" type="text" value="0"/>

Notice the name and ID attributes the BillingRate indexes are handled nicely but the BillingRateRows has no index instead ‘.item.’. From my reasearch this is because the context has been pulled out due to the foreach loop, the loop shouldn’t be necessary.

I want to achieve:-

<input name="BillingMatrix.BillingRateRows[0].BillingRates[0].Rate" id="BillingMatrix_BillingRateRows_0_BillingRates_0__Rate" style="width: 20px;" type="text" value="0"/>

If I change the BillingRateRow View to:-

@model WIP_Data_Migration.Models.ViewModels.BillingRateRowViewModel

<tr>
    @Html.EditorFor(m => Model.BillingRates)
</tr>

It will throw an InvalidOperationException, ‘model item passed into the dictionary is of type System.Collections.ObjectModel.Collection [BillingRateRowViewModel] but this dictionary required a type of BillingRateRowViewModel.

Can anyone shed any light on 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-06-13T18:11:13+00:00Added an answer on June 13, 2026 at 6:11 pm

    I’m guessing here, but it may be because you’re passing the template name in to the helper. Try one of two options. Either rename the template to match the type (ie. BillingRateRows.cshtml) or use a UIHintAttribute on the model:

    public class BillingMatrixViewModel
    {
        [UIHint("BillingRateRow")]
        public ICollection<BillingRateRowViewModel> BillingRateRows { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have everything working fine with mvc.razor generator. Views from my library project show up
Im working in MVC 3 with Razor views. I've created a page that calls
I am working on asp.net MVC 3 application. I have created a Razor view
I have been working on this MVC 3 Razor app and typically utilize view
In my ASP.net MVC App (using Razor views) I have a ProductDetails view. This
I am working on ASP.net MVC 3.0 Razor View Engine Application. I have a
I am working in asp.net MVC 3 application with Razor view. I have string
I am working on creating a blog with ASP.Net 4, MVC 3, Razor and
I am working in ASP.NET MVC 3 application, I am using razor view. I
I'm trying to get nested master pages working with the new razor syntax. Any

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.