Note that there are some explanatory texts on larger screens.

plurals
  1. POEditing a Variable Length List, ASP.NET MVC 3 Style with Table
    primarykey
    data
    text
    <p>I am following Steven Sanderson's blog post <a href="http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/" rel="nofollow">here</a> to create an editable and variable length list of items. In his post he uses divs to display a new item in the list but I am using a table. Thus, my partial view for each item is rendering a tr tag with the various fields to edit. Right now my partial view looks something like this:</p> <pre><code>&lt;tr&gt; @using (Html.BeginCollectionItem("LineItems")) { &lt;td&gt; @Html.TextBoxFor(m =&gt; m.Description) @Html.ValidationMessageFor(m =&gt; m.Description) &lt;/td&gt; &lt;td&gt; @Html.TextBoxFor(m =&gt; m.Quantity) @Html.ValidationMessageFor(m =&gt; m.Quantity) &lt;/td&gt; &lt;td&gt; @Html.TextBoxFor(m =&gt; m.Amount) @Html.ValidationMessageFor(m =&gt; m.Amount) &lt;/td&gt; } &lt;/tr&gt; </code></pre> <p>This actually renders correctly on all browsers I have tested but the problem is that this really generates invalid HTML as it places a hidden input tag right after the opening tr tag. </p> <pre><code>&lt;tr&gt; &lt;input type="hidden" name="LineItems.index" .... /&gt; &lt;td&gt; ... &lt;/td&gt; ... &lt;/tr&gt; </code></pre> <p>There is a comment by another user on the linked post that says you can move the using statement into the first tag and it works but I haven't been able to get this to work using ASP.NET MVC 3 and the Razor view engine.</p> <p>Does anyone have any idea how to use the logic presented by Steven Sanderson but get the hidden index input field inside the first td so as not to generate invalid HTML?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload