【问题标题】:HTML table not formatting properly in C#C# 中的 HTML 表格格式不正确
【发布时间】:2020-10-07 08:31:08
【问题描述】:

我正在使用 C# 在 .NET 中开发 API。我正在尝试发送格式正确的电子邮件(当委派规则分配给特定用户时。)

这是迄今为止我尝试过的代码块。

            strings.Add("email_delegation_rule_assigned", "Delegation rule assigned ");
            strings.Add("email_delegation_rule_assigned_body",
                "Hi {senderName},<br/><br/>"
                + "The following Workflow Request/s have been submitted for your approval, in the absence of {assignerUserName} from {delegateFromDate} to {delegateFromTo}.<br/><br/>"
                + "<style>table, th, td {border: 1px solid black; }</style>"
                + "<style>th {background-color:#73c1e1; }</style>"
                + "<table>" +
                "<tr>" +
                "<th> Delegation Req# </th>" +
                "<th>Delegation<table><tr><td>From User</td><td>To User</td></tr></table></th>" +
                "<th>Effective Period<table><tr><td> From </td><td> To </td></tr></table></th>" +
                "<th> List of Workflows </th>" +
                "</tr>" +
                "<tr>" +
                "<td>1</td>" +
                "<td><table><tr><td> {assignerUserName} </td><td> You </td></tr></table></td>" +
                "<td><table><tr><td>{delegateFromDate}</td><td>{delegateFromTo}</td></tr></table></td>" +
                "<td>{workflowName}</td>" +
                "</tr>" +
                "</table><br/><br/>" +
                "For further information please contact<br/><br/>" +
                "You can view the Delegation details by clicking on the link below, using Flowdoh Workspace/Form Designer<br/><br/>" +
                "Thank you!<br/>" +
                "Warm Regards,<br/>" +
                "Enadoc Team<br/><br/>"
                );

我收到这种格式的电子邮件,这是错误的格式。

我的电子邮件应该是这样的......

将单列分成两列时如何正确对齐行? th 列与 td 值不一致。 ..我需要在表格中有单行。 (忽略标题中的背景颜色)

请帮帮我。我非常感谢您的回复。提前谢谢你!

【问题讨论】:

标签: c# html .net visual-studio html-email


【解决方案1】:

您需要使用 colspan 和 rowspan 属性而不是单独的表格来进行布局。这是一个例子

<style>table, th, td {border: 1px solid black; }</style>
<style>th {background-color:#73c1e1; }</style>
<table>
  <tr>
    <th rowspan="2"> Delegation Req# </th>
    <th colspan="2">Delegation</th>
    <th colspan="2">Effective Period</th>
    <th rowspan="2"> List of Workflows </th>
  </tr>
  <tr>
    <th>From User</th><th>To User</th>
    <th>From</th><th>To</th>
  </tr>
  <tr>
    <td>1</td>
    <td>{assignerUserName}</td>
    <td> You </td>
    <td>{delegateFromDate}</td>
    <td>{delegateFromTo}</td>
    <td>{workflowName}</td>
  </tr>
</table>

https://jsfiddle.net/cx58syn0/

【讨论】:

  • @schewechel 非常感谢。你知道如何设计单行表吗?而不是双线?
  • Colspan 在电子邮件客户端中无法正常工作campaignmonitor.com/css/columns/column-span
  • @M.Sachintha 如果您要问的话,我不知道有一种方法可以使这样的标题在一行而不是两行中工作。如果您指的是单元格周围的边框,您应该可以通过一些样式来修复它table {border-collapse: collapse;}Jsfiddle 如果您想看到它,请使用此更改。 (jsfiddle.net/qxoktm40)
【解决方案2】:

看来你需要这个。

所以 HTML 代码应该是

    <table border="1">
  <tr>
    <th scope="col" rowspan="2">Delegation Req#</th>
    <th scope="col" colspan="2">Delegation</th>
    <th scope="col" colspan="2">Effective Period</th>
    <th scope="col" rowspan="2">List of workflows</th>
  </tr>
  <tr>
    <td>From User</td>
    <td>To User</td>
    <td>From</td>
    <td>To</td>
  </tr>
  <tr>
    <th scope="row">1</th>
    <td>Admin</td>
    <td>You</td>
    <td>16/16/2020 18:30:00 PM (UTC)</td>
    <td>17/16/2020 18:30:00 PM (UTC)</td>
    <th scope="row">Workflow 06/15001</th>
  </tr>
   <tr>
    <th scope="row">2</th>
    <td>Admin1</td>
    <td>You2</td>
    <td>18/16/2020 18:30:00 PM (UTC)</td>
    <td>19/16/2020 18:30:00 PM (UTC)</td>
    <th scope="row">Workflow 06/15001</th>
  </tr>
</table>

【讨论】:

  • 感谢@Damith 的回复。您的答案似乎相同。
猜你喜欢
  • 2020-07-28
  • 2016-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多