'How to download a file via an ActionResult method?

I have this controller endpoint where an form can be submitted, and and in case a specific form is being is being used it should "autodownload" a file generated based on the input provided from the user.

How do I go about this?

I have tried this

  public ActionResult SubmitForm()
  {
     if(specificForm)
     {
        byte[] file = GenerateFile(Request)
        return File(file, "application/x-pkcs7-certificates", "cer.p7b");
     }
     ...
     return ()
     
  }

but no download seem to start, I assume its because the controller force it to be an action result rather than a FilecontentResult?

How do I go about this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source