JQuery function for HTML button has problems with MVC FileResult

I wanted this function to call my MVC action method, which returns a CSV report.

$(function() {
    $('#exportButton').click(function() {
        $.get('/curReport/GetCSVReport');
    });
});

If I make a button similar to the code below, then when it is pressed, the "Open with / Save file" window will open.

<input type="button" value="Export" onClick="location.href='CurReport/GetCSVReport'">

However, when I change my button to use my jQuery function, although it GetCSVReport()is being called, they do not give me the "Open with / Save file" window.

Here is my GetCSVReport()

public FileResult GetCSVReport()
{
    ...
    return fileResult;
}

How can I make my jQuery function work like onClick?

Thank,

Aaron

+3
source share
1 answer

Use the same code that you used before:

$(function() {
    $('#exportButton').click(function() {
        location.href = 'CurReport/GetCSVReport';
    });
});

get Ajax, . jQuery , .

, :

location.href = 'CurReport/GetCSVReport?filter=' + escape(val);
+8

Source: https://habr.com/ru/post/1739168/


All Articles