I have an ASP.NET MVC application. On one page, I have a button that allows the user to download the CSV file based on some values on the page specified by the user (sliders ranges, check boxes, etc.) without leaving the page. The file is returned by my Controller class with a method that returns a FileResult.
Currently, my javascript onClickmethod is implemented as follows: jQuery bit:
function DownloadCSV() {
var url = <%=Action("DownloadCSV", "Controller")%> + '?' +
$.param({
SomeValue: $("#valuefromform").val(),
OtherValue: $("#anothervaluefromform").val(),
...
});
window.location = url;
}
This part works fine, so the question is: is it possible to rewrite this method so that it "sends" the request and does not use the "get" request line?
(I tried using an AJAX request that POST might work fine, but although I am returning the file data, this is part of the XHR response, and I cannot figure out how to make it loadable as a file, so if there is a way to do it in such a way that it was would be great!)
source
share