Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>[HttpPost] public virtual ActionResult SaveData(int movieId, FormCollection form) { // Get movie to update Movie movie = db.Movies.Where(x =&gt; x.Id == movieId); // Update movie object with values from form collection. TryUpdateModel(movie, form); // Do model validation if (!ModelState.IsValid) return View(); return View("success"); } </code></pre> <p><strong>Edit</strong> See this question I asked a while back: <a href="https://stackoverflow.com/questions/5070399/how-to-use-multiple-form-elements-in-asp-net-mvc">How to use multiple form elements in ASP.NET MVC</a></p> <p>Lets say you have a view like this:</p> <pre><code>@model IEnumerable&lt;CustomObject&gt; @foreach (CustomObject customObject in Model) { &lt;div&gt; @Html.TextBox(customObject.CustomProperty); &lt;!-- etc etc etc --&gt; &lt;/div&gt; } </code></pre> <p>Refactor it like this:</p> <pre><code>@model IEnumerable&lt;CustomObject&gt; @for (int count = 0; count &lt; Model.Count(); count++) { &lt;div&gt; &lt;!-- Add a place for the id to be stored. --&gt; @Html.HiddenFor(x =&gt; x[count].Id); @Html.TextBoxFor(x =&gt; x[count].CustomProperty); &lt;!-- etc etc etc --&gt; &lt;/div&gt; } </code></pre> <p>Now in your action method do this:</p> <pre><code>public virtual ActionResult SaveData(IEnumerable&lt;CustomObject&gt;) { // You now have a list of custom objects with their IDs intact. } </code></pre> <p>It's even easier than that if you use editors, but I'll let you figure those out for yourself as they are super simple. The accepted answer in the question I linked shows an example.</p> <p><strong>NOTE:</strong> you can substitute IList for IEnumerable if you need to.</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