Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do a bulk persist on a partial view?
    primarykey
    data
    text
    <p>I have written a partial view that displays a list of rows, where some fields in the row are editable using a textbox, checkbox, or whatever.</p> <p>I would like the parent view to have a "submit" button that posts the whole collection of updated rows so that I can do a group update rather than posting once for every updated row.</p> <p>Here's what I have:</p> <pre><code>public class GroupModel { public string SomeGenericProperty { get; set; } public IEnumerable&lt;ItemModel&gt; Items { get; set; } } public class ItemModel { public long ID { get; set; } public string Field1 { get; set; } public string Field2 { get; set; } } </code></pre> <p>Then I have a view "GroupDetails":</p> <pre><code>@model MyNamespace.GroupModel ... @using (Html.BeginForm("SaveItems", "Home")) { &lt;fieldset&gt; ... @Html.Partial("ItemList", Model.Items) ... &lt;input type="submit" value="Approve" /&gt; &lt;/fieldset&gt; } </code></pre> <p>And a partial view "ItemList":</p> <pre><code>@model IEnumerable&lt;MyNamespace.ItemModel&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt; &amp;nbsp; Field 1 &amp;nbsp; &lt;/th&gt; &lt;th&gt; &amp;nbsp; Field 2 &amp;nbsp; &lt;/th&gt; &lt;th&gt; &lt;/th&gt; &lt;/tr&gt; @foreach (var item in Model) { &lt;tr&gt; &lt;td&gt; &amp;nbsp; @Html.TextBoxFor(modelItem =&gt; item.Field1) &amp;nbsp; &lt;/td&gt; &lt;td&gt; &amp;nbsp; @Html.TextBoxFor(modelItem =&gt; item.Field2) &amp;nbsp; &lt;/td&gt; &lt;td&gt; @Html.HiddenFor(i =&gt; item.ID) &lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; </code></pre> <p>But when I post, the information from partial view is not being posted; the <code>GroupModel</code> object's <code>Items</code> property is null.</p> <p>What's the right way to do this?</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.
    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