HTMLTABLE和TagBuilder之间的差异(QUOT;表") [英] Difference between HtmlTable and TagBuilder("table")
问题描述
只是想知道不同的是这两个,什么一个或其他人利益之间的什么,当我建立我的表将是我的HtmlHelper
Just wondering what the difference is between these two and what the benefit for one or the other of them would be when I build my table in my HtmlHelper
HtmlTable table = new HtmlTable();
和
TagBuilder table = new TagBuilder("table");
这是或多或少一样这个问题,
This is more or less the same as this question,
<一个href=\"http://stackoverflow.com/questions/3043654/why-use-tagbuilder-instead-of-stringbuilder\">http://stackoverflow.com/questions/3043654/why-use-tagbuilder-instead-of-stringbuilder
但我想知道更具体的了解这两者之间的区别。
but I'm wondering more specifically about the difference between these two .
推荐答案
的主要区别是, HTMLTABLE
为所有的有效HTML属性类型和正确命名属性&LT;表&gt;
元素(例如宽度
,身高
, CELLSPACING
等)。它还具有行
属性是 HtmlTableRow
A 对象,每个reresent的类型集合&LT; TR方式&gt;
元素
The main difference is that HtmlTable
provides typed and correctly named properties for all the valid HTML attributes of the <table>
element (e.g. Width
, Height
, CellSpacing
, etc). It also has the Rows
property which is a typed collection of HtmlTableRow
objects which each reresent a <tr>
element.
TagBuilder
是一个更通用的API,它当然可以用于构建一个HTML &LT;表&gt;
,但你需要在一个不太类型安全,少容易阅读的方式做更多的工作。
TagBuilder
is a much more generic API which could certainly be used to construct an HTML <table>
but you'd need to do more work in a less type safe and less easy to read way.
一个具体的例子,其中 HmlTable
帮助的方式, TagBuilder
并不在<$的设置C $ C> WIDTH =的属性&LT;表&gt;
元素
One concrete example where HmlTable
helps in a way that TagBuilder
does not is in the setting of the width=""
attribute on the <table>
element.
使用 HTMLTABLE
:
HtmlTable htmlTable = new HtmlTable();
htmlTable.Width = "100px";
使用 TagBuilder
:
TagBuilder tagBuilder = new TagBuilder("table");
tagBuilder.Attributes["width"] = "100px";
请注意,与 TagBuilder
这两个元素的名称,表
和属性的名称,宽度
,是其引入的错误(拼写错误)两次机会时使用 HTMLTABLE
。
Note that with TagBuilder
both the name of the element, table
, and the name of the attribute, width
, are strings which introduce two opportunities for error (misspellings) that do not occur when using HtmlTable
.
这篇关于HTMLTABLE和TagBuilder之间的差异(QUOT;表&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!