Csv文件没有下载

时间:2016-04-05 10:28:59

标签: c# asp.net-mvc-4

我想从列表中下载.csv文件。我正在为此编写代码,但文件不会下载

以下是我的代码:

List<AssetsDto> assetList = client.DownloadCsv(sessionData.CompanyId, locationId, assetStage, projectType, projectId, labelSize, labelMaterial, searchText, isSearch);
        StringBuilder sb = new StringBuilder();
        sb.Append(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", "Asset Id", "Sub Id", "Child Id", "BarCode", "QRCode", "No Of Barcode", "Label Content", "Label Size", "Label Header", "HW") + Environment.NewLine);

        foreach (AssetsDto singleRecord in assetList)
        {
            sb.Append(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", singleRecord.AssetId.ToString(), singleRecord.SubAssetId, singleRecord.SplitId, singleRecord.Barcode, singleRecord.QrText, singleRecord.Quantity.ToString(), singleRecord.LabelContent, singleRecord.LabelSize, singleRecord.Header, singleRecord.HW) + Environment.NewLine);
        }



        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=SqlExport.csv");
        Response.Charset = "";
        Response.ContentType = "application/text";
        Response.Output.Write(sb.ToString());
        Response.Flush();
        Response.End();
        ViewData["PrintLabelCount"] = assetList == null ? 0 : assetList.Count();
        ViewData["LabelMaterial"] = labelMaterial;
        return PartialView("_PrintAssetListWithPaging", assetList);

0 个答案:

没有答案