title: Razor - Passing DropDownList selected value to Controller via Ajax.BeginForm
body: <p>I am trying to pass the dropdownlist value to my controller so I can add the values to a list of paycodes but I keep getting a "Value cannot be null." error. My paycode list has many items in it. Not sure what is null or wrong here...</p>
  
  <p>INNER EXCEPTION </p>
  
  <pre><code>Value cannot be null.
  Parameter name: source
  </code></pre>
  
  <p>VIEW</p>
  
  <pre><code>        &lt;!-- products input--&gt;
          &lt;div class="control-group col-lg-6"&gt;
              &lt;label class="control-label"&gt;Product&lt;/label&gt;
              &lt;div class="controls"&gt;
                  @using (Ajax.BeginForm("AddPayCode", "Referral",
      new AjaxOptions()
      {
          HttpMethod = "POST",
          InsertionMode = InsertionMode.Replace,
          UpdateTargetId = "PayCodes",
          Url = Url.Action("AddPayCode", "Referral")
      }))
                  {
                      @Html.ValidationSummary()
  
                      @Html.DropDownListFor(model =&gt; model.SelectedPayCode, new SelectList(Model.PayCodes.ToList(), "Id", "Description"), "- Select -")
                      &lt;input type="submit" value="Add" /&gt;
                  }
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>CONTROLLER</p>
  
  <pre><code>[HttpPost]
  public void AddPayCode(ReferralModel model)
  {
      var test = model.SelectedPayCode;
      //TODO: Add to model.Referral.PayCodes list and return list of selected items
  }
  </code></pre>
  
  <p>MODEL</p>
  
  <pre><code>public class ReferralModel
  {
      public Customer Customer { get; set; }
      public Employee Employee { get; set; }
      public List&lt;PayCode&gt; PayCodes { get; set; }
      public int SelectedPayCode { get; set; }
  
      public Referral Referral { get; set; }
  }
  </code></pre>
  
  <p>DOMAIN OBJECT</p>
  
  <pre><code>public class Referral
  {
      [Key]
      public int Id { get; set; }
      public int CustomerId { get; set; }
      public int EmployeeId { get; set; }
      public decimal Total { get; set; }
  
      public virtual List&lt;PayCode&gt; PayCodes { get; set; }
      public virtual Customer Customer { get; set; }
      public virtual Employee Employee { get; set; }
  }
  </code></pre>
  
  <p>Objective : </p>
  
  <ul>
  <li><p>User chooses a paycode from the dropdown and clicks "Add" Paycode is</p></li>
  <li><p>added to the referral PayCodes list</p></li>
  <li><p>Controller returns the list of    paycodes selected to the view (not
  yet implemented)</p></li>
  </ul>