简体   繁体   中英

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?

Turned out that the site was being redirected to another page. Which caused the response to never reach the user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM