Simple class for render html struct
var result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
_create.Tag("div");
result = _create.Render();
}
// output: <div></div>
create self-contained tag
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
_create.Tag("br", selfClose: true);
_result = _create.Render();
}
// output: <br/>
create tag with attributes
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
_create.Tag("div", withAttributes: new { id = "testId", @class = "testClass" });
_result = _create.Render();
}
// output: <div id='testId' class='testClass'></div>
create tag with nested tags
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
_create.Tag("div", withAttributes: new { id = "testId", @class = "testClass" }, withChildren: () =>
{
_create.Tag("span", withChildren: () =>
{
_create.Text("hello world");
});
});
_result = _create.Render();
}
// output: <div id='testId' class='testClass'><span>hello world</span></div>
create tag with attribute without value
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
_create.Tag("div", withAttributes: new { ngApp = "" });
_result = _create.Render();
}
// output: <div ng-app></div>
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
_create.Tag("div", withChildren: () =>
{
_create.Script("alert(123);", useStrict: true);
});
_result = _create.Render();
}
// output: <div><script>'use strict';alert(123);</script></div>
- name myBigAttr transform to my-big-attr
- don`t start attribute name with UpperCase