I'm sending 3 items to my controller, "From","To","StudentID" ..
I get the in LinQ and I want to pass this result to browser as a CSV file to download it, but I don't know what to write in my view to get this result,
Here is my controller:
public FileContentResult DownloadFile(String from,String to,int StudentID)
{
var myResult = (from t in db.students
where( t.date>=from && t.date<=to ) && t.studentID==StudentID
select new student {
stName = t.name,
st.fname = t.name
}).toList();
var st = DataTag.NoExlusion;
var csvByte = ASCIIEncoding
.ACII
.GetBytes( CSVexport.getCsv(myResult.toList(),st );
return this.File(csvByte,"text/csv",".csv");
}
My View
var data = { "StudentID": id, "from": frm_, "to": to_ };
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("DownloadFile", "Students")",
contentType: "application/json;charset=utf-8",
data: JSON.stringify(data),
success: function (result) {
}
})