title: ASP.NET MVC 3 - edit items dynamically added to model collection in jquery dialog
body: <p>I'm new to MVC, so I wasn't sure what the best approach would be here.</p>
  
  <p>I have a view model that contains several collections like this:</p>
  
  <pre><code>public class MainViewModel{      
      public List&lt;AViewModel&gt; A { get; set; }
      public List&lt;BViewModel&gt; B {get; set; }
      ...}
  </code></pre>
  
  <p>I'm using Steve Sanderson's approach <a href="http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/">here</a> to dynamically add items to a collection, and it's working fine as long as the child items are editable on the main view.</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>    &lt;div class="AEditorRow"&gt;
      @using (Html.BeginCollectionItem("A"))
      {                                                                 
          @Html.DisplayFor(l =&gt; l.ID)                
  
          @Html.DisplayFor(l =&gt; l.Name)
  
          @Html.DisplayFor(l =&gt; l.Code)
  
          &lt;a href="#" onclick="$('#detailsPopup').html($(this).parent().find('.ADetails').html() ).dialog()"&gt;edit&lt;/a&gt; &lt;text&gt;|&lt;/text&gt;
          &lt;a href="#" class="deleteRow"&gt;delete&lt;/a&gt; 
  
          &lt;div class="ADetails" style="display: none"&gt;
   @using (Html.BeginForm("EditA", "Controller"))
              {&lt;fieldset&gt;
                  &lt;legend&gt;Location&lt;/legend&gt;
                  @Html.HiddenFor(model =&gt; model.ID)
                  &lt;div class="editor-label"&gt;
                      @Html.LabelFor(model =&gt; model.Code)
                  &lt;/div&gt;   
  </code></pre>
  
  <p>Does anyone know of a better way to do this?</p>