0
我開始工作Asp.Net Mvc Html helper
與tagbuilder
。我正在嘗試創建一個tagbuilder
的表格,當我看到源代碼時,會創建表格,但不會創建tr
和td
。我錯在哪裏?tagbuilder沒有顯示在源
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()
完美。萬分感謝。 – Kurkula
Jarvan,如果tr中有3個tds,tr.innerHtml將如何顯示? – Kurkula
AABBCC。我不知道什麼是貴點,3個TDS在TR,tr.innerHtml肯定會在3個TDS是不是? – jarvanJiang