Note that there are some explanatory texts on larger screens.

plurals
  1. POSending an array via json to ActionMethod resutls in missing values
    text
    copied!<p>I have an object like this:</p> <pre><code>var lot = { ID: 0, ... //various other attributes SchemeInstanceList: [] } </code></pre> <p>After creation I fill the SchemeInstanceList attribute with objects of another structure like this:</p> <pre><code>lot.SchemeInstanceList.push({ ID: 0, LotID: 0, SchemeID: 18, LotPosition: 0}) </code></pre> <p>Until here, everything is fine. Now I send the lot object to my ActionMethod, creating a database entry.</p> <pre><code>$.ajax({ url: "/Lots/CreateSchemes", data: lot }); public ActionResult CreateSchemes(LotModel lot) { ... //store lot in database } </code></pre> <p>The ActionMethod gets called and the values of lot are correct, there are entries in the SchemeInstanceList. All of these entries' attributes are zero however and I don't see what I'm doing wrong.</p> <p>When I pass a single list element itself, the entries appear correctly:</p> <pre><code>$.ajax({ url: "/Lots/CreateScheme", data: lot.SchemeInstanceList[0] } public ActionResult CreateScheme(SchemeInstanceModel scheme) { ... //do whatever } </code></pre> <p>Now the SchemeID value is 18 instead of 0.</p> <p>Why isn't this working? What most obvious thing am I missing?</p> <p><strong>EDIT</strong>: Here are my models:</p> <pre><code>public class LotModel { public int ID { get; set; } ... //various other properties public List&lt;SchemeInstanceModel&gt; SchemeInstanceList { get; set; } } public class SchemeInstanceModel { public int ID { get; set; } public int LotID { get; set; } public int SchemeID { get; set; } public int LotPosition { get; set; } //public List&lt;AttributeInstanceModel&gt; AttributeInstanceList { get; set; } } </code></pre>
 

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