I am new to MVC, so I was not sure what the best approach would be here.
I have a presentation model that contains several such collections:
public class MainViewModel{ public List<AViewModel> A { get; set; } public List<BViewModel> B {get; set; } ...}
I use the Steve Sanderson approach here to dynamically add items to the collection, and it works fine while the children are being edited on the main view.
I'm having a problem returning a read-only list with an edit link that will open the details for editing in a pop-up dialog box.
Since these elements can be recently added, I cannot use the ID property to return a partial view from the controller. It looks like I have to display editors in a hidden div like this:
<div class="AEditorRow"> @using (Html.BeginCollectionItem("A")) { @Html.DisplayFor(l => l.ID) @Html.DisplayFor(l => l.Name) @Html.DisplayFor(l => l.Code) <a href="#" onclick="$('#detailsPopup').html($(this).parent().find('.ADetails').html() ).dialog()">edit</a> <text>|</text> <a href="#" class="deleteRow">delete</a> <div class="ADetails" style="display: none"> @using (Html.BeginForm("EditA", "Controller")) {<fieldset> <legend>Location</legend> @Html.HiddenFor(model => model.ID) <div class="editor-label"> @Html.LabelFor(model => model.Code) </div>
Does anyone know how best to do this?
source share