How to create nested <ul> <li> tags with HtmlTags (FubuMVC)

試著忘記壹切 提交于 2019-12-08 19:52:34

I can give you an example which may make things clearer to you:

var ul = new HtmlTag("span").AddClass("form_input");
ul.Modify(t =>
{
           foreach (var value in choice)
           {
               t.Add("input")
                   .Attr("type", "radio")
                   .Attr("name", request.Accessor.Name)
                   .Attr("value", value)
                 .Add("span")
                   .AddClass("fixed-width")
                   .Text(value);
           }
});

Gives you something like

<span class="form-input">
  <input type="radio" name="bla" value="foo" />
  <span class="fixed-width">foo</span>
  ...etc...
</span>

You can carry on nesting tags with modify and filling in the lambda. I think you will find that what you want to do is possible with the bits of syntax shown.

This code:

var root = new HtmlTags.HtmlTag("ul");
root.Add("li").Text("item1");
var child = root.Add("ul");
child.Add("li").Text("item2");
return root.ToPrettyString();

produces the following output:

<ul>
  <li>item1</li><ul>
    <li>item2</li>
  </ul>
</ul>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!