I want to pass the values I get from my elements to the controller using Javascript. I want to pass startdate
, enddate
and true
if the region
checkbox is checked.
Please note that the script also performs an extract functionality which is already working. I just want to know how I can pass those three parameters to the controller. Thanks
$(function() {
var startdate = document.getElementById("StartDate").value;
var endDate = document.getElementById("EndDate").value;
var regionname = document.getElementById("RegionName").checked;
console.log(regionname);
$("#btn-go").click(function() {
$.ajax({
type: "GET",
url: '@Url.Action("GenerateExporttReport", "Reports")',
xhrFields: {
responseType: 'blob'
},
success: function(result) {
console.log(result)
var blob = result;
var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = downloadUrl;
a.download = "downloadFile.xlsx";
document.body.appendChild(a);
a.click();
}
});
});
});
public FileContentResult GenerateExportReport(string startdate, string endDate, bool regionname)
{
// Code already exists here
}