title: How to redirect a ASP.NET Core MVC partial view after file download
body: <p>I have an asp.net core MVC partial view called ExportPagePartial that allows user to export a page from the system and downloads it. In the HttpGet controller action I show the partial view (as a Modal pop-up) to get user input.</p>
  
  <p><strong>Modal Popup</strong></p>
  
  <pre><code>&lt;a class="dropdown-item" asp-action="ExportPagePartial" asp-route-userId="@Model.UserId" asp-route-businessAccountId="@Model.BusinessAccountId" asp-route-projectId="@Model.ProjectId" asp-route-pageId="@Model.PageId" data-toggle="modal" data-target="#ModalPlaceholder" title="Export page."&gt;&lt;i class="fas fa-cloud-download-alt"&gt;&lt;/i&gt; &amp;nbsp; Export&lt;/a&gt;
  </code></pre>
  
  <p><strong>Controller Get Action</strong></p>
  
  <pre><code>[HttpGet]
  public IActionResult ExportPagePartial(string userId, string businessAccountId, string projectId, string pageId)
  {       
      ExportPageViewModel model = new ExportPageViewModel()
      {
         // Set properties
      };
  
      return PartialView(nameof(ExportPagePartial), model);
  }
  </code></pre>
  
  <p>Once the user hits Export button from the Modal pop-up partial view (which is a form submit action) the following HTTPPost action is correctly called.
  In this action I have to get the file from the Web Api and then download it via the browser, however after download is complete i want to close the partial view. Once the download is complete the partial view is still visible.</p>
  
  <p>The return action never works and partial modal pop-up view does not close
  <strong>return RedirectToAction(nameof(BlahRedirectAction));</strong></p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public async Task&lt;IActionResult&gt; ExportPagePartial(ExportPageViewModel model)
   {
              // Call Web API to get the file              
              string downloadUrl = "blah_blah_url";
              using (HttpResponseMessage httpResponse = await WebApiClient.HttpClient.PostAsJsonAsync(downloadUrl, unprotectedExportInput))
                  {
                      if (!httpResponse.IsSuccessStatusCode)
                      {
                          throw new InvalidOperationException(await httpResponse.Content.ReadAsStringAsync());
                      }
  
                      // Download the file now.
                      ActionContext actionContext = new ActionContext(HttpContext, ControllerContext.RouteData, ControllerContext.ActionDescriptor, ModelState);
                      FileStreamResult fileContent = File(await httpResponse.Content.ReadAsStreamAsync(), httpResponse.Content.Headers.ContentType.MediaType, httpResponse.Content.Headers.ContentDisposition.FileName);
                      await fileContent.ExecuteResultAsync(actionContext);
                  }
  
              // Redirect to main pain
              // The view never redirects and partial view is still visible
              return RedirectToAction(nameof(BlahRedirectAction));
   }
  </code></pre>