Use of the file FileResult exported by ASP. NET, asp. netfileresult

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.