title: Passing input parameters to controller method via Html.ActionLink
body: <p>When the user clicks on an <code>Html.ActionLink</code>, I need to call a controller method that will download a <code>csv</code> report for the user. I also need to pass this controller the values from two input boxes that will denote a start and end date range they're looking for. </p>
  
  <p>Currently I can assign the <code>Html.ActionLink</code> parameters using jQuery, however they are not making it back to the controller. Both parameters in the controller method are instantiated with <code>null</code> values. </p>
  
  <p>I also cannot use a form/submit method as that is already being used on this particular form to allow the users to see the data in the date range requested before exporting to the csv. </p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>$(document).ready(function() {
      $('#startDate').change(function () {
          $('a').attr('start', $(this).val());
      });
  
      $('#endDate').change(function () {
          $('a').attr('end', $(this).val());
      });
  });
  </code></pre>
  
  <p><strong>ASP MVC 3 View</strong></p>
  
  <pre><code>@using (Html.BeginForm())
  {
      &lt;div id="searchBox"&gt;
          @Html.TextBox("startDate", ViewBag.StartDate as string, new { placeholder = "   Start Date" })
          @Html.TextBox("endDate", ViewBag.EndDate as string, new { placeholder = "   End Date" })
          &lt;input type="image" src="@Url.Content("~/Content/Images/Search.bmp")" alt="Search"  id="seachImage"/&gt;
          &lt;a href="#" style="padding-left: 30px;"&gt;&lt;/a&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      @Html.ActionLink("Export to Spreadsheet", "ExportToCsv", new { start = "" , end = ""} )
      &lt;span class="error"&gt;
          @ViewBag.ErrorMessage
      &lt;/span&gt;
  }
  </code></pre>
  
  <p><strong>Controller Method</strong></p>
  
  <pre><code>    public void ExportToCsv(string start, string end)
      {
  
          var grid = new System.Web.UI.WebControls.GridView();
  
          var banks = (from b in db.AgentTransmission
                      where b.RecordStatus.Equals("C") &amp;&amp;
                            b.WelcomeLetter
                      select b)
                      .AsEnumerable()
                      .Select(x =&gt; new
                                 {
                                     LastName = x.LastName,
                                     FirstName = x.FirstName,
                                     MiddleInitial = x.MiddleInitial,
                                     EffectiveDate = x.EffectiveDate,
                                     Status = x.displayStatus,
                                     Email = x.Email,
                                     Address1 = x.LocationStreet1,
                                     Address2 = x.LocationStreet2,
                                     City = x.LocationCity,
                                     State = x.LocationState,
                                     Zip = "'" + x.LocationZip,
                                     CreatedOn = x.CreatedDate
                                 });
  
  
          grid.DataSource = banks.ToList();
          grid.DataBind();
  
          string style = @"&lt;style&gt; .textmode { mso-number-format:\@; } &lt;/style&gt; ";
  
          Response.ClearContent();
          Response.AddHeader("content-disposition", "attachment; filename=WelcomeLetterOutput.xls");
          Response.ContentType = "application/excel";
          StringWriter sw = new StringWriter();
          HtmlTextWriter htw = new HtmlTextWriter(sw);
          grid.RenderControl(htw);
          Response.Write(style);
          Response.Write(sw.ToString());
          Response.End();
      }
  </code></pre>