我需要将文本数据导出到 MVC3 中的 csv。我执行以下操作:
看法:
$(".export").click(function() {
$.get("@Url.Action("Export","Log")");
});
控制器:
public ActionResult Export()
{
var sb = new StringBuilder();
var list = this.systemLogRepository.GetFilterList(
null, this.ControllerContext.RequestContext.HttpContext.Request.QueryString, null);
foreach (var item in list)
{
sb.AppendFormat(
"{0},{1},{2},{3},{4}", item.Machine.Name, item.PackageID, item.ErrorDescription, item.OccurenceTime, Environment.NewLine);
}
return this.File(new UTF8Encoding().GetBytes(sb.ToString()), "text/csv", string.Format("Log-{0}.csv", DateTime.Now.ToString("g").Replace("/","-").Replace(":","_").Replace(" ", "-")));
}
这将返回内容,但不会弹出带有“另存为”和“打开”选项的窗口??谢谢