1
これは奇妙なことですが、私はすべての作業を行っていますが、ファイル内にあるfileStreamResult以下のコントローラコードには100の結果が84個しかありません。変数searchResultsには100個のレコードが含まれています。MVCビューからCSVへのエクスポート(Excel用)
私は実行時に制御コードをステップ場合、期待どおりループ内部「sw.WriteLine(.........」ラインが100回を実行する。
だからデータがあると思われます
デバッグ後、100個のレコードすべてにヌルやメタ文字などの奇妙なデータが含まれていないため、なぜこのようなことが起こっているのか分かりません。またはこれに関するアイデアがありますか?
マイコントローラコード:
public FileStreamResult Export(string searchText, string searchTextSite, string StartDate, string EndDate)
{
var searchResults = getSearchResults(searchText, searchTextSite, StartDate, EndDate);
HttpContext.Response.AddHeader("content-disposition", "attachment; filename=Export.csv");
var sw = new StreamWriter(new MemoryStream());
sw.WriteLine("\"Ref\",\"Source\",\"Collected\"");
foreach (var line in searchResults.ToList())
{
sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\"",
line.WasteId,
line.SourceWasteTypeId.ToDescription(),
line.CollectedDate.ToShortDateString()));
}
sw.BaseStream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(sw.BaseStream, "text/csv");
}
マニーありがとう – John