title: MVC4 Get listboxfor Text & Value properties
body: <p>In My MVC4 EF5 App i'm using 2 listboxes. each listbox is bounded to a List property of my view model.</p>
  
  <p>i would like to get all listboxes items (and i mean all SelectedListItem - Selected, Text, Value) when i submit a from.</p>
  
  <p>This is how i do so (with no sucess..)</p>
  
  <p>My View Model:</p>
  
  <pre><code>public class PriorityViewModel
  {
  
      public List&lt;SelectListItem&gt; lst_fromCEID { get; set; }
      public List&lt;SelectListItem&gt; lst_C2C { get; set; }
  
      public PriorityViewModel()
      {
          lst_C2C = new List&lt;SelectListItem&gt;();
          lst_fromCEID = new List&lt;SelectListItem&gt;();
      }
  }
  </code></pre>
  
  <p>My Action:</p>
  
  <pre><code>public ActionResult Index()
      {
          var model = new PriorityViewModel();
  
          var c2c_ceid_source = _unitOfWork.ActionRepository.GetC2C_SourceCEID();
          model.lst_fromCEID = _unitOfWork.EntityRepository.GetEntitiesByC2CSource(c2c_ceid_source);
  
          return View(model);
      }
  
      public ActionResult UpdatePriority(PriorityViewModel model)
      {
          //save manual changes to DB
          SaveManualPriorityToDB(model);
          ...
      }
  </code></pre>
  
  <p>My View:</p>
  
  <pre><code>@model TRM.Models.ViewModel.PriorityViewModel
  
  @{
      ViewBag.Title = "Index";
  }
  
  
  @*@Html.Action("Run");*@
  
  
  @using (Html.BeginForm("UpdatePriority", "Priority", FormMethod.Post))
  {
      @Html.Hidden("demoQuantity", Model.demoQuantity)
      @Html.Hidden("installQuantity", Model.installQuantity)
      @Html.Hidden("CIP_Quantity", Model.CIP_Quantity)
      @Html.Hidden("C2C_Quantity", Model.C2C_Quantity)
      &lt;table&gt;
  
          &lt;tr&gt;
              &lt;td&gt;
                  From CEID
                  @Html.ListBoxFor(model =&gt; model.lst_fromCEID, @Model.lst_fromCEID, new { width = "50px" })
              &lt;/td&gt;
  
              &lt;td style="width:50px"&gt;
                  &lt;input id="btnRemoveAllC2C" type="button" value=" &lt;&lt; " onclick="removeallItemsC2C();" /&gt;
                  &lt;input id="btnAddAllC2C" type="button" value=" &gt;&gt; " onclick="addallItemsC2C();" /&gt;
                  &lt;input id="btnAddC2C" type="button" value="  &gt; " onclick="addItemC2C();" /&gt;
                  &lt;input id="btnRemoveC2C" type="button" value="  &lt; "  onclick="removeItemC2C();" /&gt;
              &lt;/td&gt;
  
              &lt;td style="width:50px"&gt;
                  C2C
                  @Html.ListBoxFor(model =&gt; model.lst_C2C, new MultiSelectList(Model.lst_C2C), new { width = "50px" })
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;h2&gt;Install &amp; Orphan&lt;/h2&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
  
      &lt;/table&gt;
  
      &lt;input type="submit" value="Run Transition!" onclick="SelectAllItems()"/&gt;
  }
  
  @section scripts {
      &lt;script src="~/Scripts/MyScripts/PriorityScript.js"&gt;&lt;/script&gt;
  }
  </code></pre>
  
  <p>My Js File:</p>
  
  <pre><code>function addItemC2C() {
      $("#lst_fromCEID option:selected").appendTo("#lst_C2C");
      $("#lst_C2C option").attr("selected", false);
  }
  
  function addallItemsC2C() {
      $("#lst_fromCEID option").appendTo("#lst_C2C");
      $("#lst_C2C option").attr("selected", false);
  }
  
  function removeItemC2C() {
      $("#lst_C2C option:selected").appendTo("#lst_fromCEID");
      $("#lst_fromCEID option").attr("selected", false);
  }
  
  function removeallItemsC2C() {
      $("#lst_C2C option").appendTo("#lst_fromCEID");
      $("#lst_fromCEID option").attr("selected", false);
  }
  </code></pre>
  
  <p>if i set the viewModel properties to List i can get the listbox text out on button submit. but this is not enough for me, i need Text and Value.</p>
  
  <p>Thx..</p>