如何在.ajax post中处理FileStream返回类型?

如何在.ajax post中处理FileStream返回类型?,ajax,asp.net-mvc,actionlink,actionresult,Ajax,Asp.net Mvc,Actionlink,Actionresult,我通过以下代码发送JSON对象控制器返回CSV格式的值,这些值应提供promt以打开或另存为CSV文件。我无法理解在success:function(result)中究竟应该编写什么代码 出口链接 Html.ActionLink("Export", "", "", null, new { @onclick = "return exportData();"}) function exportData() { var searchViewModel = getExLogSearchModelDa

我通过以下代码发送JSON对象控制器返回CSV格式的值,这些值应提供promt以打开或另存为CSV文件。我无法理解在success:function(result)中究竟应该编写什么代码

出口链接

Html.ActionLink("Export", "", "", null, new { @onclick = "return exportData();"})

function exportData() {

var searchViewModel = getExLogSearchModelData();
var path = getAbsolutePath("ExclusionLog", "ExportData");
$.ajax({
    url: path,
    cache: false,
    contentType: 'application/json; charset=utf-8',
    dataType: 'html',
    type: 'POST',
    data: JSON.stringify(searchViewModel),
    success: function (result) {
    },
    error: function (error) {
        $("#voidcontainer").html("Error");
    }
});
}

控制器操作结果

    public ActionResult ExportData(ExclusionLogSearchViewModel postSearchViewModel)
    {
        try
        {
            IEnumerable<ExclusionLogViewModel> exclusionLogData = null;
            exclusionLogcData = this._workerService.GetExclusionLogData(postSearchViewModel);

            return CSVFile(exclusionLogMembershipSyncData.GetStream<ExclusionLogViewModel>(), "ExclusionLogTables.Csv");
        }
        catch (Exception ex)
        {
                throw ex;
        }
        return null;
    }
public ActionResult导出数据(排除LogSearchViewModel postSearchViewModel)
{
尝试
{
IEnumerable ExclutionLogData=null;
ExclutionLogCDATA=this.\u workerService.getExclutionLogData(postSearchViewModel);
返回CSVFile(ExclutionLogMembershipSyncData.GetStream(),“ExclutionLogTables.Csv”);
}
捕获(例外情况除外)
{
掷骰子;
}
返回null;
}

你能建议一下怎么做吗?

我遇到了同样的问题,我没有找到使用
$下载文件的方法。ajax
但是我发现了一个优秀的JavaScript库,它提供了类似的行为:

您只需要调用如下内容:

$.fileDownload(path, {
    httpMethod: 'POST',
    data: JSON.stringify(searchViewModel),
    success: function (result) {
    },
    error: function (error) {
        $("#voidcontainer").html("Error");
    }
});
记住在控制器中创建cookie。在
src/Common
中,有适合您的操作过滤器