title: How to download a file on button click on a Razor page?
body: <p>I have an XML file being generated filled with information from the Razor page, and I want to download this generated XML file on the click of a download button. I'm new to Razor pages, and returning the XML file as a FileResult isn't working for me. Guidance on what to write for my <code>&lt;a&gt;</code> and how to set up the C# annotations, etc would be very helpful.</p>
  
  <p>My .cshtml code is:</p>
  
  <pre><code>&lt;br/&gt; 
  @Html.ActionLink("Link name", "SaveFile", "EditLicense", 
          new { 
             LicenseFileJson = JsonConvert.SerializeObject(Model.License) 
          }) 
  &lt;br/&gt; 
  </code></pre>
  
  <p>When this gets displayed on the page I get:</p>
  
  <pre><code>&lt;br/&gt; &lt;a href=""&gt;Link name&lt;/a&gt;&lt;br/&gt; 
  </code></pre>
  
  <p>and clicking it does nothing.</p>
  
  <p>My action code is:  </p>
  
  <pre><code>public class EditLicenseController : Controller
  {
      public FileResult SaveFile(string LicenseFileJson)
      {
          License License = (License)JsonConvert.DeserializeObject(LicenseFileJson);
          LicenseTool tool = new LicenseTool(License);
          string licenseFileString = tool.ToFileString();
          byte[] bytes = Encoding.ASCII.GetBytes(licenseFileString);
          var stream = new MemoryStream();
          var writer = new StreamWriter(stream);
          writer.Write(licenseFileString);
          writer.Flush();            
          Response.Headers.Add("Content-Disposition", "attachment;");
          return File(bytes, "text/xml", "testing123.xml");
      }
      ...
  </code></pre>
  
  <p>When I click the link I also don't see anything indicating this is working in the Network tab of chrome dev tools.</p>