任何人都可以幫助我在.html
頁面中使用if statement
。在.html模板頁面中使用if語句(在<span>標記中)
我有一個etemplate.html
頁面。在其<span>
標籤裏面,我有一些{values}
,我從後面的代碼填充。這樣的:在C#中
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<div style="border-top:3px solid #22BCE5"> </div>
<span style="font-family:Arial;font-size:10pt">
Hi <b>{Name}</b>,<br /><br />
Thank you for your order. Your project ID is {ProjId}. Your order
description is {description}.<br /><br />
// for {summary} == "" the below code shows if(!=""){---...
//I have tried using <% %> tags but not working
if({summary}!=""){
Your project summary is {summary}.
}
</span>
</body>
</html>
我的填充方法是:
private string PopulateConfirmationEmailBody(string Name, string ProjId,
string description, string summary)
{
string body = string.Empty;
using (StreamReader reader = new
StreamReader(Server.MapPath("~/etemplate.html")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{Name}", Name);
body = body.Replace("{ProjId}", ProjId);
body = body.Replace("{description}", description);
body = body.Replace("{summary}", summary);
return body;
}
任何幫助,將不勝感激。提前致謝..!!
選中此:https://forums.asp.net/t/1944993.aspx?How+to+use+if+else+condition+to+display+text+in+HTML+ – Sujith
@Sujith感謝您建議,但正如我所提到的,我已經嘗試使用<% %>,但不工作 – Preet
現在你實際上沒有做任何事情來運行你的HTML代碼。你需要通過像Razor這樣的解析器運行它,它將運行嵌入式代碼並輸出純html。 – juharr