迭代List<>在发送邮件时在message.body中使用foreach循环?

时间:2014-01-16 04:36:59

标签: html asp.net generics

在我的asp.net应用程序中发送邮件,该邮件检查符合促销条件的员工列表并发送该员工列表

我需要这种模式

 The following Employees Are eligible for promotion:

 xyz
 abc

员工姓名在列表中,我需要在msg.body中使用foreach循环并遍历该列表但是它给我一些语法错误,是否可以在html中循环?

msg.Body = "The following Employees Are eligible for promotion <br/><br/>Employee Name: '"  "'";



this is my List
      List<string> myList = UserForPromotion.Split(',').ToList();

1 个答案:

答案 0 :(得分:0)

您可以使用StringBuilder构建邮件正文。首先确保在.cs文件的顶部有此语句:

using System.Text;

然后像这样迭代myList

StringBuilder sb = new StringBuilder();
sb.Append("The following Employees Are eligible for promotion <br/><br/>Employee Name:");
foreach (string name in myList)
{
    sb.AppendFormat("<br/>{0}", name);
}

msg.Body = sb.ToString();