I have a MVC4 C# project using Entity Framework and I want to know how I can update multiple child entities from a parent entity.
I am using a view model to send the data from the two models to the view:
public class ResultData
{
public Result Result { get; set; }
public IEnumerable<ResultNote> ResultNotes { get; set; }
}
So I’m wanting to update all of Result’s notes on the Result Edit form.
My View:
@model RSC3_DB.ViewModels.ResultData
@foreach (var note in Model.ResultNotes)
{
<div class="editor-field">
@Html.EditorFor(model => note.NoteText)
@Html.ValidationMessageFor(model => note.NoteText)
</div>
}
This renders them on the form correctly. My question is what do I need to put in the Result controller “[HttpPost]ActionResult Edit” method to make the changes to the ResultNotes?
Turns out you just have to use a for loop with assigned an assigned index value and list each model attribute out.