Q:

HTML Button's jQuery function is having trouble with MVC FileResult

I intended for this function to call my MVC action method that returns a CSV report.
$(function() {
    $('#exportButton').click(function() {
        $.get('/curReport/GetCSVReport');
    });
});

If I make a button like the code below then, when it is clicked, I'm given the "Open with/Save File" window.
<input type="button" value="Export" onClick="location.href='CurReport/GetCSVReport'">

However, when I change my button to use my jQuery function then, although GetCSVReport() is called I'm not given the "Open with/Save File" window.
Here is my GetCSVReport()
public FileResult GetCSVReport()
{
    ...
    return fileResult;
}

How can I get my jQuery function to work like the onClick?
Thank you,
Aaron

A:

Use the same code you used before:
$(function() {
    $('#exportButton').click(function() {
        location.href = 'CurReport/GetCSVReport';
    });
});

get triggers an Ajax call, which you do not want here. You use jQuery to bind the event, but the action stays the same.
To add query string parameters, use:
location.href = 'CurReport/GetCSVReport?filter=' + escape(val);

