我能够保存字符串" aaa"通过在视图中使用此代码到用户的本地计算机c:\ myDir \ myFile.txt:
var Test = function() {
var sSelection = getselection();
$.get('/Archive/Save',
{ 'selection': sSelection },
function (response) {
var fso = new ActiveXObject("Scripting.FileSystemObject"),
theFile = fso.CreateTextFile("C:\\myDir\\myFile.txt", true);
theFile.Write('aaa'); //--->> Successfully write "aaa" to c:\myDir\myFile.txt
theFile.Close();
}
);
}
但是,Controller返回FileStreamResult,当我执行以下代码时,我收到错误" JavaScript运行时错误:无效的过程调用或参数":
var Test = function() {
var sSelection = getselection();
$.get('/Archive/Save',
{ 'selection': sSelection },
function (response) {
var fso = new ActiveXObject("Scripting.FileSystemObject"),
data = response, // this is FileStreamResult
theFile = fso.CreateTextFile("C:\\myDir\\myFile.txt", true);
theFile.Write(data); //----->>> JavaScript runtime error: Invalid procedure call or argument
theFile.Close();
}
);
}
这是Controller中的代码:
public ActionResult Save(string selection)
{
int cnt = SetTempData(selection);
FileStreamResult fs = ArcTicket(0);
return fs;
}
如何将FileStreamResult保存到文件中? 谢谢。