I'm new to MVC, so I wasn't sure what the best approach would be here.
I have a view model that contains several collections like this:
public class MainViewModel{
public List<AViewModel> A { get; set; }
public List<BViewModel> B {get; set; }
...}
I'm using Steve Sanderson's approach here to dynamically add items to a collection, and it's working fine as long as the child items are editable on the main view.
The problem I'm having is returning a read only list with an edit link that will open the details to edit in a popup dialog.
Since these items may be newly added, I can't use the ID property to return a partial view from the controller. It seems like I'll have to render the 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 of a better way to do this?