String.Format 带有包含 html 的字符串

mat*_*564 -2 c# sql database sql-server asp.net-web-api

我正在开发一个从数据库中获取电子邮件模板然后发送它们的应用程序。

来自数据库的模板的正文有 html,我如何在这个字符串上做一个 String.Format ?目前我收到一条错误消息,说输入字符串的格式不正确。

    <!DOCTYPE html>
<html>
<head>
</head>
<body>
    <style>
        .container {
            font-size: 0;
        }

            .container.p.span {
                /*font-size: 16px;**/
            }

        .titleTextSpan {
            color: white;
            width: inherit;
            height: inherit;
            font-family: sans-serif, Arial;
            font-size: 20px;
            display: table-cell;
            vertical-align: middle;
            text-align: left;
        }
    </style>
    <div class="container" style="width:700px;">
        <div style="display:inline-block;">
        </div>
        <div style="width:700px;height:44px; background:#36A6DE;display:table;">
            <span class="titleTextSpan">PRODUCT NAME</span>
        </div>
        <div style="font-size:10pt;margin-left:20px;font-family:Arial, sans-serif;color:#4D4C4C">
            <br />
            Dear {16},
            <br /><br />
            Thank you for your request for PRODUCT NAME, which is now with your organisation approver for authorisation.
            <br />
            Call details:
            <br />
            Call number: {17}
            <br />
            Organisation Approver: {22} {23}
            <br />
            <br />
            If you have any other questions please do not hesitate to contact us.<br />
            Please email <a href="EMAIL">EMAIL</a> or contact your local team lead.
            <br />
            <br />
            Kind Regards,
            <br />
            <br />
            Intelligence Point Administrator
        </div>
        <div style="margin-top:20px;width:700px;height:10px; background:#36A6DE;display:table;"></div>
        <div style="width:700px;height:20px; background:#F1F1F1;display:table;"></div>
        <div style="width:700px;height:50px;background:#15314D;text-align:center;display:table">
            <span style="font-size:9pt; vertical-align:middle;color:#36A6DE; font-family:Arial, sans-serif;display:table-cell;">
                We welcome your comments, feedback and suggestions
            </span>
        </div>
        <div style="font-size:10pt; vertical-align:middle;color:black; font-family:Arial, sans-serif;text-align:center;">
            <b>Email:</b><a href=""> </a> | <b>Website:</b> <a href=""></a>
        </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Nil*_*dri 5

您需要使用and转义html 中的每个{and },因为 String.Format 将它们视为占位符而不是您的 css 规则。顺便说一句,在实际使用 String.Format 之前,您可以使用 String.Replace 替换任何其他字段的值{{}}