我有一个 C# 方法,它返回包含 HTML 标记的字符串文字。最初,我硬编码了一个 URL,但现在我想生成一个动态 URL。但是,我遇到了错误,可能是由于语法不正确,但我无法确定确切的问题。
有人可以帮助我确定哪里出了问题或者是什么导致了问题?
private static string LoadRemovedSheetTemplate(string url)
{
return @"<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset=utf-8 />
</head>
<body style=""margin: 0; padding: 10px; box-sizing: border-box;background-color: #f9f9fa;margin: 20px;"">
<div class=""container""
style=""margin: 0; padding: 0; box-sizing: border-box;background-color: #f9f9fa; margin-left: auto; margin-right: auto; width: max-content;"">
<div class=""main-content-section""
style=""background-color: #fff;height: 600px;margin-bottom: 20px; box-shadow: rgba(0, 0, 0, 0.02) 0px 1px 3px 0px, rgba(27, 31, 35, 0.15) 0px 0px 0px 1px;padding: 25px; height: max-content; width: max-content;"">
<div class=""top-logo-section"" style=""text-align: center;"">
<div style=""height: 100px; margin-bottom: 10px;"">
<img src=""https://dwihn.org//images/logo.png"" alt=""BizAnalytix Technologies"" style=""height: 100%;"" />
</div>
</div>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">Dear {2},</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">
Claim has been removed from the audit {3}.
</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">
<a href=""localhost:54400/AuditProject/OngoingAudits"">Click here</a> to view.
</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">Thank You,</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">CATS Support</p>
<div class=""bottom-logo-section"" style=""text-align: center;"">
<div style=""margin:0;"">
<p style=""font-size: 14px;
font-family: sans-serif;
color: #000000;"">
Powered By:
</p>
<img src=""https://bizanalytix.com/wp-content/uploads/2020/12/BizAnalytix-New-Logo.png"" style=""height:50px;"" />
</div>
</div>
</div>
</div>
</body>
</html>";
}
在这里
<a href=""localhost:54400/AuditProject/OngoingAudits"">
我想用我在函数中得到的url替换localhost
我尝试了这种方法,
<a href=" + url + /AuditProject/OngoingAudits">
,但它给出了很多错误。
private static string LoadRemovedSheetTemplate(string url)
{
return @"<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset=utf-8 />
</head>
<body style=""margin: 0; padding: 10px; box-sizing: border-box;background-color: #f9f9fa;margin: 20px;"">
<div class=""container""
style=""margin: 0; padding: 0; box-sizing: border-box;background-color: #f9f9fa; margin-left: auto; margin-right: auto; width: max-content;"">
<div class=""main-content-section""
style=""background-color: #fff;height: 600px;margin-bottom: 20px; box-shadow: rgba(0, 0, 0, 0.02) 0px 1px 3px 0px, rgba(27, 31, 35, 0.15) 0px 0px 0px 1px;padding: 25px; height: max-content; width: max-content;"">
<div class=""top-logo-section"" style=""text-align: center;"">
<div style=""height: 100px; margin-bottom: 10px;"">
<img src=""https://dwihn.org//images/logo.png"" alt=""BizAnalytix Technologies"" style=""height: 100%;"" />
</div>
</div>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">Dear {2},</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">
Claim has been removed from the audit {3}.
</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">
<a href=" + url + /AuditProject/OngoingAudits">Click here</a> to view.
</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">Thank You,</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">CATS Support</p>
<div class=""bottom-logo-section"" style=""text-align: center;"">
<div style=""margin:0;"">
<p style=""font-size: 14px;
font-family: sans-serif;
color: #000000;"">
Powered By:
</p>
<img src=""https://bizanalytix.com/wp-content/uploads/2020/12/BizAnalytix-New-Logo.png"" style=""height:50px;"" />
</div>
</div>
</div>
</div>
</body>
</html>";
}
在第二种方法中,您尝试将 url 变量直接连接到 HTML 字符串中。但是,语法不正确,因为您没有正确地将连接的字符串括在双引号内。
return @"<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset=utf-8 />
</head>
<body style=""margin: 0; padding: 10px; box-sizing: border-box;background-color: #f9f9fa;margin: 20px;"">
<div class=""container""
style=""margin: 0; padding: 0; box-sizing: border-box;background-color: #f9f9fa; margin-left: auto; margin-right: auto; width: max-content;"">
<div class=""main-content-section""
style=""background-color: #fff;height: 600px;margin-bottom: 20px; box-shadow: rgba(0, 0, 0, 0.02) 0px 1px 3px 0px, rgba(27, 31, 35, 0.15) 0px 0px 0px 1px;padding: 25px; height: max-content; width: max-content;"">
<div class=""top-logo-section"" style=""text-align: center;"">
<div style=""height: 100px; margin-bottom: 10px;"">
<img src=""https://dwihn.org//images/logo.png"" alt=""BizAnalytix Technologies"" style=""height: 100%;"" />
</div>
</div>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">Dear {2},</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">
Claim has been removed from the audit {3}.
</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">
<a href=""" + url + @"/AuditProject/OngoingAudits"">Click here</a> to view.
</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">Thank You,</p>
<p style=""font-size: 14px;
font-family: sans-serif;
line-height: 25px;
color: #000000;
letter-spacing: 0.2px;"">CATS Support</p>
<div class=""bottom-logo-section"" style=""text-align: center;"">
<div style=""margin:0;"">
<p style=""font-size: 14px;
font-family: sans-serif;
color: #000000;"">
Powered By:
</p>
<img src=""https://bizanalytix.com/wp-content/uploads/2020/12/BizAnalytix-New-Logo.png"" style=""height:50px;"" />
</div>
</div>
</div>
</div>
</body>
</html>";