Use of the file FileResult exported by ASP. NET, asp. netfileresult
This article will show you how to use FileResult in ASP. net mvc to export files. First of all, there are many examples on the Internet. I just want to make a little difference here --Why is my export unresponsive?
I haven't found this question for a long time. I finally learned it in a comments from a netizen. The details are as follows:
First, we export data in the background in the simplest way (everything is simplified ):
Public FileResult Export () {return File (Server. MapPath ("/Data/Export.xls"), "application/ms-excel", "Export.xls ");}
Second, we need to call it at the front end. There are many calling methods. I choose to use js to call:
<Script type = "text/javascript"> window. location. href = "Export"; </script>
In fact, the code in js is very simple. In just one sentence, there is no problem in calling and exporting. Why does someone encounter "export has no effect or response ?", Because you put this js Code in ajax, if you encounter such problems, try again to see if the export is successful.
I have seen a lot of great gods. The summary is very well done. I won't be able to learn it at half past one, so there is a point first.
ASP. net mvc: Using FileResult to send files to a browser
MVC 3 let's take a look at the ActionResult as many younger siblings.
Asp. Net MVC use FileResult to export Excel Data Files