我正在尝试在电子邮件正文中显示取件号列表。我可以使用以下代码获得优惠号码:
foreach (LoadRelationship relationship in View.SelectedObjects)
{
///This works fine, I get 3 pickup numbers for my selected records///
List<string> pickUpNumbers = View.SelectedObjects.Cast<LoadRelationship>()
.Where(x => x != null && x.PurchaseLoad.PickupNumber != null)
.Select(x => x.PurchaseLoad.PickupNumber)
.ToList();
//When assigning the pickUpNumbers.To String to the body of the email it fails here:
e.Report.ExportOptions.Email.Body = pickUpNumbers.ToString();
}
电子邮件正文中的输出是:
System.Collections.Generic.List`1 [System.String]
输出应该是这样的:
12345 2334556 12334445
答案 0 :(得分:3)
试试这个:
e.Report.ExportOptions.Email.Body = string.Join(" ", pickUpNumbers);
答案 1 :(得分:1)
尝试:
foreach (LoadRelationship relationship in View.SelectedObjects)
{
///This works fine, I get 3 pickup numbers for my selected records///
List<string> pickUpNumbers = View.SelectedObjects.Cast<LoadRelationship>()
.Where(x => x != null && x.PurchaseLoad.PickupNumber != null)
.Select(x => x.PurchaseLoad.PickupNumber)
.ToList();
//When assigning the pickUpNumbers.To String to the body of the email it fails here:
string body = "";
for(int i = 0; i < pickUpNumbers.Count; i++) {
if (i > 0) {
body += ", ";
}
body += puckUpNumbers[i];
}
e.Report.ExportOptions.Email.Body = body;
}
答案 2 :(得分:1)
输出为System.Collections.Generic.List1[System.String]
,因为您有一组字符串并且直接在集合上调用.ToString()
。
您可以通过遍历集合并构建电子邮件正文来获得所需的结果。
例如:
StringBuilder sb = new StringBuilder();
foreach(var pickupNumber in pickUpNumbers) {
sb.Append(pickupNumber);
}
e.Report.ExportOptions.Email.Body = sb.ToString();
您也可以使用String.Join
。
e.Report.ExportOptions.Email.Body = string.Join(" ", pickUpNumbers);