【问题标题】:Add 2 parameters to Email Template Body向电子邮件模板正文添加 2 个参数
【发布时间】:2019-05-27 12:16:54
【问题描述】:

我有一个电子邮件模板,我已经绑定了 1 个参数(this.OrderCode)并且它正在工作。所以现在我需要绑定另一个。

电子邮件模板如下,

string OrderTemplate="<p><%=this.OrderCode%></p><p><%=this.ReferredTo%></p>";

tempValues comes like below,
[0]this.OrderCode
[1]ODR5000
[2]this.ReferredTo
[3]Janez Smithson

使用下面的代码我需要显示以上两个值。这里只显示第一个值(ODR5000)

public string EmailTemplate(string OrderTemplate, params string[] tempValues)
        {
            string templatebody = string.Empty;
            try
            {
                templatebody = OrderTemplate;
                for (var i = 0; i < tempValues.Length; i++)
                {
                    templatebody= templatebody.Replace("<%={0}%>".FormatWith(tempValues[i]), tempValues++);
                }
            }
            catch (Exception ex)
            {
                throw ex;
                Log4NetLogger.Log(ex);
            }
            return templatebody;
        }

【问题讨论】:

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


    【解决方案1】:

    我有非常相似的功能。

    for (int i = 0; i < tempValues.Length; i++)
    {
        var pattern = string.Format(@"(\[{0}\])", i);
        templatebody = Regex.Replace(templatebody, pattern, tempValues[i].ToString());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-29
      • 2010-12-20
      • 2017-03-11
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多