title: How do I get my ActionResult method to return a file for download and the Partial View?
body: <p>After following <a href="https://stackoverflow.com/a/23068430/1466627">this</a> answer, by using <code>Response</code> to return the Excel XLS file, the <code>ActionResult</code> returns the <code>PartialView</code> as it is supposed to, but then it does not give me a XLS file to download.</p>
  
  <p>Form on SearchItems.cshtml:</p>
  
  <pre><code>@using (Ajax.BeginForm(new AjaxOptions { 
      HttpMethod = "Get",
      InsertionMode = InsertionMode.Replace,
      UpdateTargetId = "grid_searchitems" })) {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;Entity Search&lt;/legend&gt;
          &lt;div class="editor-label"&gt;
                  @Html.Label("Select an Item Purpose:")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.ListBox(
                  "Purpose",
                  new MultiSelectList((Model as List&lt;MyWeb.Models.SearchItemModel&gt;).Select(a =&gt; a.Purpose).Distinct().ToList().OrderBy(a =&gt; a)),
                  new {
              @class = "chosen-select",
                      data_placeholder = "Choose a function code"
                  })
          &lt;/div&gt;
          &lt;p&gt;
              &lt;input type="submit" value="Search" name="ButtonType"/&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  &lt;div id="gridContainer"&gt;
      @Html.Partial("_SearchItems") @* See _SearchItem.cshtml (below) for WebGrid *@
  &lt;/div&gt;
  </code></pre>
  
  <p>_SearchItem.cshtml Partial View containing the <code>WebGrid</code></p>
  
  <pre><code>@{
      var grid = new WebGrid(ViewData.Model, ajaxUpdateContainerId: "grid_searchitems", rowsPerPage: 25);
  }
  
  &lt;style type="text/css"&gt;
      .webgrid-table td {
          text-align: left;
          vertical-align: top;
      }
  &lt;/style&gt;
  
  &lt;div id="grid_searchitems"&gt;
      @grid.GetHtml(
          tableStyle: "webgrid-table",
          alternatingRowStyle: "alternate",
          headerStyle: "header",
          columns: grid.Columns(
              grid.Column("Name", "Item Name"),
              grid.Column("Purpose", "Purpose"),
          )
      )
  &lt;/div&gt;
  </code></pre>
  
  <p>ActionResult Method that is hit when the Submit button is clicked</p>
  
  <pre><code>public ActionResult SearchModes(string[] Purpose = null) {
      List&lt;SearchItemModel&gt; items = DBContext.Items.ToList();
      GridView gv = new GridView();
      gv.DataSource = items;
      gv.DataBind();
      Response.ClearContent();
      Response.Buffer = true;
      Response.AddHeader("content-disposition", "attachment; filename=SearchResults.xls");
      Response.ContentType = "application/vnd.ms-excel";
      Response.Charset = "";
      StringWriter sw = new StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      gv.RenderControl(htw);
      Response.Output.Write(sw.ToString());
      Response.Flush();
      Response.End(); // &lt;-- Is this where the "download" is supposed to be received on the client?
  
      ViewData.Model = items;
      //AJAX request is generated when submit button clicked
      if (Request.IsAjaxRequest()) {
          // Return only the changed entities
          return PartialView("_SearchItems"); // &lt;-- This works
      }
      else {
          // Return entire view
          return View();
      }
  }
  </code></pre>
  
  <p>In the end, I want to be able to have the user click <code>Search</code> then ability to save the results XLS file, while having the results shown in the returned <code>Partial View</code>. I'd like to be able, eventually, to have two Submit buttons, where one is just for querying, and the other for querying and exporting (reason why I'm using the <code>name</code> attribute).</p>