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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:46:13+00:00 2026-05-27T16:46:13+00:00

I have an Entity (QuoteSheet) that contains a child entity (QuoteTask), which is loaded

  • 0

I have an Entity (QuoteSheet) that contains a child entity (QuoteTask), which is loaded using the EntityFramework. However, I am receiving an error when I submit this form.

I have created an edit page for the QuoteSheet entity, which then uses an EditorTemplate to edit the QuoteTask child entity.

The controller code is as follows:

public ActionResult TestEdit(int Id)
{
    var quote = DataContext.QuoteSheets.Where(x => x.ID == Id).FirstOrDefault();
    return View(quote);
}

[HttpPost]
public ActionResult TestEdit(Models.QuoteSheet quote)
{
    return View(quote);
}

A stripped down version of the view is as follows:

@using (Html.BeginForm())
{ 
@Html.ValidationSummary(true)
@Html.HiddenFor(x => x.JobID);

<div class="sectionHeader">Sheet Details</div>
<div class="sectionContent">
    <table>
        <tr>
            <td width="150">Sheet Desc.</td><td>@Html.TextBoxFor(x => x.Description, new { size = "50" })</td>
        </tr>
        <tr>
            <td>Quantity Required</td><td>@Html.EditorFor(x => x.Quantity)</td>
        </tr>
    </table>
</div>

<div class="sectionHeader">Tasks</div>
<div class="sectionContent">
    <table id="Tasks">
        <tr>
            <th>Labour Group</th>
            <th>Task Description</th>
            <th>Total Hrs</th>
            <th>Rate</th>
            <th>Cost</th>
        </tr>
        @Html.EditorFor(x => x.QuoteTasks)
    </table>
    <input type="button" name="AddTasks" id="AddTasks" value="Add" />
</div>

<input type="submit" value="Submit" />

@Html.ValidationSummary()
}

And the EditorTemplate is:

@model Ornavi.Models.QuoteTask



<tr>
    <td>@Html.EditorFor(x => Model.LabourGroup)</td>
    <td>@Html.EditorFor(x => Model.Description)</td>
    <td>@Html.EditorFor(x => Model.TotalHours)</td>
    <td>@Html.EditorFor(x => Model.Rate)</td>
    <td>@Html.HiddenFor(x => Model.ID)</td>
</tr>

When I submit the form, I am getting the following error:

The EntityCollection has already been initialized. The InitializeRelatedCollection method should only be called to initialize a new EntityCollection during deserialization of an object graph.

This only occurs when I use the EditorTemplate – if I remove the editor template and just submit the main entity, it works fine.

I have placed a breakpoint in the [httppost] TestEdit function, but the exception occurs before it reaches this point.

Any ideas on how to successfully use an EditorTemplate to edit a child entity?

  • 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-27T16:46:13+00:00Added an answer on May 27, 2026 at 4:46 pm

    The problem is, that the default modelbinder tries to instantiate your EF class and set the navigation properties when binding the form data to your parameter types.

    See some similar questions like this one.

    You have two options:

    1. Don’t use your EF classes as viewmodels but create own viewmodel classes to pass the data between controller and view.

    2. Don’t bind directly to the EF class in your Edit controller action but use a FormCollection parameter and bind yourself with UpdateModel as shown in the linked question.

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

Sidebar

Related Questions

I have some entity types that I would like to lazy load. However, they
I have entity Ideas, which has child entity collection ChildIdeas. I need to load
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have entity e.g. Product which aggregates other entities such as Category . Those
In my business model I have Entity class (IPoint interface ) that has a
I have an entity loaded by Hibernate (via EntityManager ): User u = em.load(User.class,
I have an entity which looks something like this: (I'm coding to the web
I have Person entity which has composition with Location Entity @ManyToOne(fetch = FetchType.EAGER, cascade
In entity framework I have an Entity 'Client' that was generated from a database.

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.