我向我的控制器发送3个项目,"从","到"," StudentID" ..
我收到了LinQ,我希望将此结果作为CSV文件传递给浏览器进行下载,但我不知道在我的视图中要写什么来获得此结果,
这是我的控制器:
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");
}
我的观点
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) {
}
})