我开始Asp.Net Mvc Html helper
使用tagbuilder
. 我正在尝试使用 and 创建一个表,tagbuilder
当我看到源时,表已创建但不是tr
and td
。我在哪里错过了重点?
public static HtmlString TbTile(this HtmlHelper helper)
{
TagBuilder tagBuilder = new TagBuilder("table");
tagBuilder.Attributes["style"] = "background-color:red;height:200px;";
tagBuilder.Attributes["width"] = "100%";
tagBuilder.Attributes["border"] = "1";
TagBuilder tbody = new TagBuilder("tbody");
TagBuilder tr = new TagBuilder("tr");
TagBuilder td = new TagBuilder("td");
TagBuilder th = new TagBuilder("th");
td.Attributes["style"] = "background-color:green;height:100px;";
td.Attributes["height"] = "50%";
td.InnerHtml = "test td1";
return new HtmlString(tagBuilder.ToString());
}
@Html.TbTile()