Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try something like this.</p> <p>Suppose you have this object :</p> <pre><code>public class Vehicle { public int VehicleID { get; set; } public string LicencePlate { get; set; } public string Color { get; set; } } </code></pre> <p>And this is your controller action that you'll use to edit vehicle details (where you'll post the form) :</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult EditVehicles(int Owner, Vehicle[] vehicles) { //manipulate the data, then return back to the list return RedirectToAction("YourAction"); } </code></pre> <p>Then you should set your form this way : </p> <pre><code>&lt;!--have a form for each person, listing their vehicles--&gt; &lt;form action="/EditVehicles" method="post"&gt; &lt;input type="hidden" name="Owner" value="25" /&gt; &lt;input type="hidden" name="Vehicles[0].VehicleID" value="10" /&gt; &lt;input type="text" name="Vehicles[0].LicencePlate" value="111-111" /&gt; &lt;input type="text" name="Vehicles[0].Color" value="Red" /&gt; &lt;input type="hidden" name="Vehicles[1].VehicleID" value="20" /&gt; &lt;input type="text" name="Vehicles[1].LicencePlate" value="222-222" /&gt; &lt;input type="text" name="Vehicles[1].Color" value="Blue" /&gt; &lt;input type="submit" value="Edit" /&gt; &lt;/form&gt; </code></pre> <p>This will help the DefaultModelBinder to correctly bind the form data to your model in your controller. Thus <code>Response.Write(vehicles[1].Color);</code> on your controller, will print "Blue".</p> <p>This is a very simple example, but I'm sure you get the idea. For more examples about binding forms to arrays, lists, collections, dictionaries, take a look at <a href="http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx" rel="noreferrer">here</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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