title: ASP.NET mvc : HOWTO: Update database after editing multiselectlist (listbox)
body: <p>I'm really stuck at this: I have two listboxes populated from a database. I want to copy items from one list to the other. Then the changes must be saved in the database.</p>
  
  <p>This is what I've got:</p>
  
  <p>Custom ViewModel:</p>
  
  <pre><code>public class StudentModel
      {
          public IEnumerable&lt;SelectListItem&gt; NormalStudentsList { get; set; }
          public IEnumerable&lt;SelectListItem&gt; StudentsNoClassList { get; set; }
          public string[] NormalSelected { get; set; }
          public string[] NoClassSelected { get; set; }
          public string Save { get; set; }
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult IndexStudents(Docent docent, int id, int klasgroepid)
          {
              var studentModel = new StudentModel
              {
                 NormalStudentsList = docent.GeefStudentenNormaalList(id, klasgroepid),
                 StudentsNoClassList = docent.GeefStudentenNoClassList(id, klasgroepid)
              };
  
              return View(studentModel);
          }
  
          [HttpPost, Authorize]
          public ActionResult IndexStudentsResult(StudentModel model, string add, string remove)
          {
              ModelState.Clear();
             (if! string.IsNullOrEmpty(add))
                 //update database
              SaveState(model);
              return View(model);
          }
  </code></pre>
  
  <p>But how can I update the database?? Using UpdateModel()?
  or should I work with FormCollection? But I need a formCollection to work with UpdateModel()...
  The Students table has a field named "ClassID", and when copying the rows from 1 list to the other, the ID has to change from the current ClassID to "0".</p>
  
  <p>How can I do that? I'm really stuck at this... hope you can help.</p>
  
  <p>This is my View</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"  Inherits="System.Web.Mvc.ViewPage&lt;ProjectenII.Models.Domain.StudentModel&gt;"%&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt;
      IndexStudents
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;h2&gt;IndexStudents&lt;/h2&gt;
  
    &lt;%using (Html.BeginForm()) { %&gt;
      &lt;%=Html.ListBoxFor(model =&gt; model.NormalSelected, new MultiSelectList(Model.NormalStudentsList, "StudentNummer", "Naam", Model.NormalSelected), new { size = "6" }); %&gt;
  
      &lt;input type="submit" name="add" 
                            id="add" value="&gt;&gt;" /&gt;&lt;br /&gt;
      &lt;%=Html.ListBoxFor(model =&gt; model.NoClassSelected, new MultiSelectList(Model.StudentsNoClassList, "StudentNummer", "Naam", Model.NoClassSelected)); %&gt;
    &lt;% } %&gt;
  
    &lt;%=Html.HiddenFor(model =&gt; model.Save) %&gt;
    &lt;input type="submit" name="apply" id="apply" value="Save!" /&gt;
  &lt;/asp:Content&gt;
  </code></pre>