私のアクションの1つは、csvファイルを出力します。問題は、フィールドにコンマが含まれている場合、データ行が2つのフィールドに分割されることです。「\」を使用して各行を二重引用符で囲んでみましたが、機能しません。誰かが正しい方向に案内してくれますか?
アップデート
var sw = new StringWriter();
sw.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}", "First Name","Last Name","Address1","Address2","City","State","Postal Code","Country","Dealer ID","Dealer Name","Survey Source","Amount","Email","Survey Code"));
sw.WriteLine(String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",\"{9}\",\"{10}\",\"{11}\",\"{12}\",\"{13}\"", model.SurveyWinnerDetails.Select(p => p.FirstName).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.LastName).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.Address1).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.Address2).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.City).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.State).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.PostalCode).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.CountryCode).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.DealerID).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.DealerName).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.SurveySource).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.Amount).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.Email).First().Replace("\"", "\"\""),
model.SurveyWinnerDetails.Select(p => p.SurveyCode).First().Replace("\"", "\"\"")));
return File(new System.Text.UTF8Encoding().GetBytes(sw.ToString()), "text/csv", "SurveyWinner.csv");
これを今実行すると、エラーが発生します:オブジェクト参照がオブジェクトのインスタンスに設定されていません。