我创建了一个字符串,用于生成HTML表格。但是,我无法将文本显示为HTML格式,它只会作为纯文本进行写入。
这里是我创建字符串的代码:
StringBuilder HTMLTable = new StringBuilder(); HTMLTable.AppendLine("<html>");
HTMLTable.AppendLine("<head>");
HTMLTable.AppendLine("<style type=\"text/css\">");
HTMLTable.AppendLine(" .thd {background: rgb(220,220,220); font: bold 10pt Arial; text-align: center;}");
HTMLTable.AppendLine(" .team {color: white; background: rgb(100,100,100); font: bold 10pt Arial; border-right: solid 2px black;}");
HTMLTable.AppendLine(" .winner {color: white; background: rgb(60,60,60); font: bold 10pt Arial;}");
HTMLTable.AppendLine(" .vs {font: bold 7pt Arial; border-right: solid 2px black;}");
HTMLTable.AppendLine(" td, th {padding: 3px 15px; border-right: dotted 2px rgb(200,200,200); text-align: right;}");
HTMLTable.AppendLine(" h1 {font: bold 14pt Arial; margin-top: 24pt;}");
HTMLTable.AppendLine("</style>");
HTMLTable.AppendLine("</head>");
HTMLTable.AppendLine("</html>");
HTMLTable.AppendLine("<body>");
HTMLTable.AppendLine("<h1>Tournament Results</h1>");
HTMLTable.AppendLine("<table border=\"0\" cellspacing=\"0\">");
for (int row = 0; row <= max_rows; row++)
{
cumulative_matches = 0;
HTMLTable.AppendLine(" <tr>");
//等等等等
然后我将这个字符串添加到与我的.cshtml文件相关联的viewbag中。我尝试过以下方法:
<text>@ViewBag.bracketHTML</text>
但是那样做不起作用。有什么想法吗?
</html>
出现在<body>
之前。它不应该放在标记的最后面吗(在</body>
之后)? - Zhihao