Note that there are some explanatory texts on larger screens.

plurals
  1. POASP MVC submit list not mapping all values
    primarykey
    data
    text
    <p>I have a table where the user can add a entry and once the user is done they they can add another.</p> <p>After they added a entry they can remove it again. This is where the problem happens. Here is an example</p> <p>ACTION:</p> <pre><code>Public ActionResult Submit(List&lt;String&gt; Names) { //DO STUFF } </code></pre> <p>When they add a entry it will grab the index of the previous entry and add a hidden field for it, so at the end it will look something like this:</p> <p>HTML:</p> <pre><code> &lt;input type="hidden" name='Names[0]' value='John'/&gt; &lt;input type='hidden' name='Names[1]' value='Peter' /&gt; &lt;input type='hidden' name='Names[2] value='David' /&gt; </code></pre> <p>When I submit this it will map all the names correcty. The problem is that the user can remove one of the names after they added it before the submit. If they remove the input with the value 'Peter' the html will look like this</p> <p>HTML AFTER REMOVE:</p> <pre><code> &lt;input type="hidden" name='Names[0]' value='John'/&gt; &lt;input type='hidden' name='Names[2] value='David' /&gt; </code></pre> <p>When this gets submitted, only the input with the value 'John', will get mapped.</p> <p>Does anyone know how to fix this without coding a jquery function that will redo all the indexes in the html? I'm looking for a solution that I can add server side for the bindings, a override or something. The reason I don't want to do it with jquery is because I have multiple pages that has such functionality, and doing it for each page will be quite time time consuming.</p> <p><em><strong></em>**<em>*</em>**</strong><em>EDIT</em><strong><em>*</em>**<em>*</em>***</strong></p> <p>The code above are just an example, one of my models that I try to bind look like the following:</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>And then obviously in my Action</p> <pre><code>public ActionResult Submit(List&lt;namespace.Product&gt; Products) { //do stuff } </code></pre>
    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