Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to Zabavsky comment, I found the solution I was looking for.</p> <p>I used non-sequential indices.</p> <p>Here is an example:</p> <p>Action:</p> <pre><code> public ActionResult Create(List&lt;namespace.Product&gt; Products) { //do stuff } </code></pre> <p>Model:</p> <pre><code>public class Product { public string Code {get;set;} public string Name {get;set;} public int Quantity {get;set;} public decimal Price {get;set;} } </code></pre> <p>In my form the html will look like the following:</p> <pre><code>&lt;input type='hidden' name='Products.Index' value='1'/&gt; &lt;input type='hidden' name='Products[1].Code' value='xyz' /&gt; &lt;input type='hidden' name='Products[1].Name' value='Shirt' /&gt; &lt;input type='hidden' name='Products[1].Quantity' value='5'/&gt; &lt;input type='hidden' name='Products[1].Price' value='50'/&gt; &lt;input type='hidden' name='Products.Index' value='7'/&gt; &lt;input type='hidden' name='Products[7].Code' value='zxy' /&gt; &lt;input type='hidden' name='Products[7].Name' value='Pants' /&gt; &lt;input type='hidden' name='Products[7].Quantity' value='8'/&gt; &lt;input type='hidden' name='Products[7].Price' value='70'/&gt; &lt;input type='hidden' name='Products.Index' value='foo'/&gt; &lt;input type='hidden' name='Products[foo].Code' value='1234' /&gt; &lt;input type='hidden' name='Products[foo].Name' value='Shoes' /&gt; &lt;input type='hidden' name='Products[foo].Quantity' value='2'/&gt; &lt;input type='hidden' name='Products[foo].Price' value='100'/&gt; </code></pre> <p>All these will bind correctly. All that I had to add was the:</p> <pre><code>&lt;input type='hidden' name='Products.Index' value='1'/&gt; </code></pre> <p>All the index values just needs to be unique for this to work, so with just a few lines of jquery I was able to achieve this.</p> <p>More information can be found here: <a href="http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx" rel="nofollow">Model Binding To A List</a></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.
    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