Note that there are some explanatory texts on larger screens.

plurals
  1. POEmpty List When Data Is Posted To Action Method (ASP .Net MVC)
    primarykey
    data
    text
    <p>I have got a problem with submitting data to Post method.</p> <p>I have a class similar to this:</p> <pre><code>public class A { public int Id{get; set;} public string Name{get; set;} public List&lt;B&gt; Bs {get; set;} } </code></pre> <p>In the View I have a list of Bs object that I can add to the Bs property of class A without any problem. I can see the result without any problem in my Razor View as well.</p> <p>The problem occurs when I post the final result to my Add Action Method to save them in my database.</p> <p>When the final object is sent to my Action method the Bs property is completely empty. So what I did instead was to add that collection to a TempData dictionary and retrieved it in my Add Action method.</p> <p>My question is simple why is my Bs property empty when its posted to my Edit action method ? The reason why I ask this is because in my AddBs action method I add my Bs to my Model and send it back to View and everything is find up to that point.</p> <p>Edit: @SLaks</p> <p>This is the code I have in my View :</p> <p>&lt;% using (Html.BeginForm("Create", "A")) { %> &lt;%: Html.ValidationSummary(true) %> </p> <pre><code> &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.Name) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.EditorFor(model =&gt; model.Name) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Name) %&gt; &lt;/div&gt; &lt;% if (Model.Bs.Any()) { %&gt; &lt;h3&gt;B List&lt;/h3&gt; &lt;%= Html.Telerik().Grid(Model.Bs) .Name("CheckedOrders") .Columns(columns =&gt; { columns.Bound(d =&gt; d.Id).Width(100); columns.Bound(d =&gt; d.Name).Width(300); }) .Footer(false) %&gt; &lt;% } %&gt; &lt;br /&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; </code></pre> <hr> <pre><code>This is the HTML generated: &lt;form action="/Admin/BusinessType/Create" method="post"&gt; &lt;fieldset&gt; &lt;div class="editor-label"&gt; &lt;label for="Name"&gt;Name&lt;/label&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;input class="text-box single-line" id="Name" name="Name" type="text" value="" /&gt; &lt;span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class="t-widget t-grid" id="CheckedOrders"&gt;&lt;table cellspacing="0"&gt;&lt;colgroup&gt;&lt;col style="width:100px" /&gt;&lt;col style="width:300px" /&gt;&lt;/colgroup&gt;&lt;thead class="t-grid-header"&gt;&lt;tr&gt;&lt;th class="t-header" scope="col"&gt;Id&lt;/th&gt;&lt;th class="t-last-header t-header" scope="col"&gt;Name&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td class="t-last"&gt;Heeey&lt;/td&gt;&lt;/tr&gt;&lt;tr class="t-alt"&gt;&lt;td&gt;3&lt;/td&gt;&lt;td class="t-last"&gt;Testtttt&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;br /&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>The Code above shows perfectly fine in my Browser, I can even see the Bs list, but when I type a Name And Click on Create, the Bs list is empty.</p>
    singulars
    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.
 

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