title: Passing Data from Controller to View using Ajax to filter results
body: <p>I'm attempting to filter my results based on a drop down selected value. All the filtering and everything is working, I'm just struggling to get my view to update with the results. I'm leaving out some brackets and other irrelevant code Here is what I have:</p>
  
  <pre><code>public ViewResult Index()
  {    
       -- this effectively returns all Invoices no matter what date --
       var data = new UserBAL().GetInvoice(date);
       return View(data);                 
  }
  </code></pre>
  
  <p>My Jquery and Ajax is :</p>
  
  <pre><code> $(document).ready(function () {
       $("[name='DDLItems']").change(function () {
           var selection = $("[name='DDLItems']").val();
           var dataToSend = {
               //variable to hold selection?
               idDate: selection
           };
  
           $.ajax({
               type: "POST",
               url: "Invoice/FilterInvoice",
               data: dataToSend,
               success: function (data) {   
                  $("#Index").html(data);                     
               }
  </code></pre>
  
  <pre class="lang-c# prettyprint-override"><code>[HttpPost]                     // Selected DDL value 
  public ActionResult FilterInvoice(int idDate)
  {       
       switch (idDate)
      { 
          case 0:
               date = DateTime.Parse("01-01-1754");
               break;
  
          case 3:
               date = DateTime.Now.AddMonths(-12);
               break;
       }
       //var data is returning my expected results 
       var data = new UserBAL().GetInvoice(date);
  
      // I know this isn't right and needs to be changed 
       return View(data);
  </code></pre>
  
  <p>My ajax success function isn't doing anything either So it i'm guessing this needs some tweaking. Also Here's how I am displaying the table using table tags. Keep in mind I left some code out but everything important is here, and the only issue is rendering my filtered results back to the view,</p>
  
  <pre><code>  @foreach (var item in Model) {
    &lt;tr&gt;&lt;td&gt;   
      @Html.DisplayFor(modelItem =&gt; item.Invoice_Number)        
      @Html.DisplayFor(modelItem =&gt; item.Amt_Total)
  &lt;/td&gt;
  </code></pre>