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);
Sheet Desc. |
@Html.TextBoxFor(x => x.Description, new { size = "50" }) |
Quantity Required |
@Html.EditorFor(x => x.Quantity) |
@Html.ValidationSummary()
}
And the EditorTemplate is:
@model Ornavi.Models.QuoteTask
@Html.EditorFor(x => Model.LabourGroup)
@Html.EditorFor(x => Model.Description)
@Html.EditorFor(x => Model.TotalHours)
@Html.EditorFor(x => Model.Rate)
@Html.HiddenFor(x => Model.ID)
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?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)