title: How to use select2 with multiple options using Razor and MVC
body: <p>I am trying to create a multiple choice list using Select2, Razor and the MVC framework. My problem is that the object in the controller that receives the array input is always null. The front-end looks as follows: </p>
  
  <pre><code>&lt;form class="form-horizontal" method="post" action="@Url.Action(MVC.Configurazione.Contatori.Edit())"&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-lg-8"&gt;
              &lt;select class="form-control attributoSelect2" name="attributiSelezionati" value="@Model.AttributiSelezionati"&gt;
                  &lt;option value="@Model.AttributiSelezionati" selected&gt;@Model.AttributoDescrizione&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The action method "Edit", is the controller method that receives the array of chosen items from the drop-down list.</p>
  
  <p>The Javascript is the following: </p>
  
  <pre><code>    $('.attributoSelect2').select2({
          placeholder: "Search attribute",
          multiple: true,
          allowClear: true,
          minimumInputLength: 0,
          ajax: {
              dataType: 'json',
              delay: 150,
              url: "@Url.Action(MVC.Configurazione.Attributi.SearchAttrubutes())",
              data: function (params) {
                  return {
                      search: params.term
                  };
              },
              processResults: function (data) {
                  return {
                      results: data.map(function (item) {
                          return {
                              id: item.Id,
                              text: item.Description
                          };
                      })
                  };
              }
          }
      });
  </code></pre>
  
  <p>And finally the C# controller has an object that is expected to retrieve the data from the view and is defined:</p>
  
  <pre><code>public string[] AttributiSelezionati { get; set; }
  </code></pre>
  
  <p>and the HttpPost method that receives the data is:</p>
  
  <pre><code>[HttpPost]
  public virtual ActionResult Edit(EditViewModel model) { }
  </code></pre>
  
  <p>Could someone give me some insight into what I am doing wrong and the areas that I should change in order to find the problem?</p>