Download File - Asp.net MVC with Jquery

前端 未结 3 2043
轻奢々
轻奢々 2021-01-15 20:50

Am dowloading a file using JQUERY MVC. User clicks on button and am downloading the File looks as simple as it is.

My Jquery Event

$         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-15 21:06

    You can do it calling your sever side via AJAX. Here's an example on how to Block your UI when you make an ajax call.

    Attach the Block/Unblock methods to the $(document).ready function. Every time an AJAX call is made, the UI is going to be blocked.

    $(document).ready(function () {
    
    }).ajaxStart(function () {
        $.blockUI();
    }).ajaxStop(function () {
        $.unblockUI();
    });
    
    $(document).on("click", "#download", function () {
        DownloadFile();
    }
    
    function DownloadFile() {
        $.ajax({
            url: "../Home/Download",
            data: { null },
            success: function (data) {
                //Do something with data that is returned. (The downloaded file?)
            }
        });
    }
    

提交回复
热议问题