Note that there are some explanatory texts on larger screens.

plurals
  1. POMvc returning null value back from view for list<> object in model
    text
    copied!<p>In an mvc 3 .Net FW 4.0 project I have a data that relates in a parent child relationship, I've built up my model to contain a list of "children" with each parent record, and displaying it as in the following example:</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/ViewMasterPage.Master" Inherits="System.Web.Mvc.ViewPage&lt;MvcTest.Models.ModelList&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; ShowPropReturn &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt;ShowPropReturn&lt;/h2&gt; &lt;script src="&lt;%: Url.Content("~/Scripts/jquery.validate.min.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;% using (Html.BeginForm()) { %&gt; &lt;%: Html.ValidationSummary(true) %&gt; &lt;fieldset&gt; &lt;legend&gt;ModelList&lt;/legend&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.MyProperty1) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.EditorFor(model =&gt; model.MyProperty1) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.MyProperty1) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.MyProperty2) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.EditorFor(model =&gt; model.MyProperty2) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.MyProperty2) %&gt; &lt;/div&gt; &lt;table&gt; &lt;% foreach (var item in Model.MyProperty3) { %&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.TextBoxFor(i =&gt; item.string1) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%: Html.TextBoxFor(i =&gt; item.string2) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; &lt;/table&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div&gt; &lt;%: Html.ActionLink("Back to List", "Index") %&gt; &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p>I figured out that if a displayfor is used to only display a field value, it does not get posted back which makes sense. But I'm getting a null for the child list object in the model on httppost and I need to have these items edited on the same view, it is also null in the formcollection object, can anyone help me on this please?</p>
 

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