Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:48:37+00:00 2026-06-13T22:48:37+00:00

I need to make a file download that displays a loading icon during the

  • 0

I need to make a file download that displays a loading icon during the processing of the file (because I don’t know how long it is going to take), I decided to use an iframe, the code runs fine, but the problem is that the file download dialog box doesn’t show up.

I’ve tested in IE, Firefox and Chrome and it is not working in any of them.

Here’s my code:

View:

<table id="progress" style="visibility:hidden">
    <tr>
        <td>
            <img src="~/Content/Images/ajax-loader.gif" />
        </td>
        <td>
            <h4>please wait.</h4>
        </td>
    </tr>
</table>

<div class="buttons">
    <input type="button" value="Ok" class="button" id="downloadButton">
</div>

<iframe id="iframe" style="visibility:hidden"></iframe>

<script>
    $(document).ready(function () {

        $('#downloadButton').click(function () {

            $('#progress').show();
            $('input:button').attr("disabled", true);

            $('#iframe').src = "@Url.Action("GenerateFile", "Files", null)";

            $('#iframe').load("GenerateFile", function () {
                $('input:button').attr("disabled", false);
                $('#progress').hide();
            });
        });

    });
</script>

Server side Action:

[HttpGet]       
public void GenerateFile(Filters viewModel)        
{        
    var result = GetCustomers().WithName(viewModel.Name);        
    StringBuilder file = new StringBuilder();

    foreach (var customer in result)        
    {        
        // fill up the string builder with csv format       
    }        

    System.Web.HttpContext.Current.Response.AddHeader("content-disposition","attachment; filename=Customers.csv");        
    System.Web.HttpContext.Current.Response.ContentType = "application/csv";        
    System.Web.HttpContext.Current.Response.Write(file);        
    System.Web.HttpContext.Current.Response.End();        
}       

Any help would be appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:48:38+00:00Added an answer on June 13, 2026 at 10:48 pm

    I think there are multiple problems with this code. Try this:

    public FileResult GenerateFile(Filters viewModel)
            {
                var result = GetCustomers().WithName(viewModel.Name);
                StringBuilder file = new StringBuilder();
    
                foreach (var customer in result)
                {
                    // fill up the string builder with csv format       
                }
                var content = Encoding.UTF8.GetBytes(file.ToString());
                return File(content, "application/csv", "Customers.csv");
            }
    

    and I think there is no jQuery method called src, so try this also:

    $('#iframe').attr('src',url);  
    

    I assume you’re using Razor syntax, so try this for your View code:

    @{
        ViewBag.Title = "Test";
    }
    
    <table id="progress" style="display: none">
        <tr>
            <td>
                <img src="~/Content/Images/ajax-loader.gif" />
            </td>
            <td>
                <h4>please wait.</h4>
            </td>
        </tr>
    </table>
    
    <div class="buttons">
        <input type="button" value="Ok" class="button" id="downloadButton">
    </div>
    
    <iframe id="iframe" style="display: none"></iframe>
    @section scripts{
        <script type="text/javascript">
            $(document).ready(function () {
    
                $('#downloadButton').click(function () {
    
                    $('#progress').show();
                    $('input:button').attr("disabled", true);
    
                    var url = "@Url.Action("GenerateFile", "Files", null)";
    $("#iframe").attr('src', url);
    
                    $('#iframe').load("/Files/GenerateFile", function () {
                        $('input:button').attr("disabled", false);
                        $('#progress').hide();
                    });
                });
    
            });
        </script>
    }
    

    And I also believe that you should specify an Action parameter in your jQuery load function, eg. $(‘#iframe’).load(“/Files/GenerateFile/parameter”…) because your GenerateFile action takes Filters parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to download file from FTP server and make some changes on it
we have some C++ code that we need to create a make file in.
I have an excel file that I need to make some changes. I need
I need to make a flat file PHP calendar that an admin would be
I'm trying to create an excel file and make that available as download. But
I need to download excel file over http. The problem is that Chrome browser
I need to make a file format for my software. The data is basic
So what I need to do is make it so a html file (without
It took me FOREVER to finally find code that can download a doc file
I need to download 100MB of images, so i decided that the best way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.