【问题标题】:Is there a lib to make html easier in C#/.NET/ASP.NET在 C#/.NET/ASP.NET 中是否有使 html 更容易的库
【发布时间】:2010-02-12 11:31:41
【问题描述】:

我记得曾经看过一个项目,一个人用某种语言编写了类似这样的东西,其中包含类似 json 的字符串,它创建了非常好的 html。有没有类似的东西可以用于 C# 或 .NET

radio-box{ AName, [First|Second|Value:9|ItsLikeAnEnum]}, TextBox[user, password],
Checkbox[RememberMe:true, blah]}  //blah is default which is false

【问题讨论】:

  • 这样容易吗?看起来并不比实际编写 html 复杂得多,而且 html 更具有自我描述性......
  • 我不知道为什么人们赞成该评论。如果 html 可以这么简单,那么上面的内容就更容易了,而且不会丢失信息。无需更改每个单选框(在上述情况下为 4 个),您只需更改一次,而不是手动执行多次或使用查找/替换出错。上面的代码更少,更容易维护。

标签: c# .net html auto-generate


【解决方案1】:

如果您使用的是 ASP.NET,则有 HTML Agility pack

它有许多处理 HTML 的助手。它与您描述的格式不完全相同,但仍然比处理原始 HTML 更容易。

来自网站:

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).

【讨论】:

    【解决方案2】:

    虽然它与您问题中的代码示例不匹配,但也许您正在寻找像 NHaml 这样的模板语言? 这是一个简短的 NHaml 示例:

    %h1 List of products
    %ul
      - foreach (var product in products)
        %li= product.Name 
    

    相当于:

    <h1>List of products</h1>
    <ul>
        <% foreach (var product in products) %>
            <li>
                <%= product.Name %>
            </li>
        <% } %>
    </ul>
    

    【讨论】:

      【解决方案3】:

      如果你看一下 ASP.NET MVC,那里有很多内置的 html 辅助方法,你的意思是这样吗?

      http://www.asp.net/mvc

      【讨论】:

        【解决方案4】:

        不完全是答案,但有TagBuilder in Asp.Net MVC

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-06-24
          • 1970-01-01
          • 1970-01-01
          • 2010-09-24
          • 2011-06-28
          • 2010-09-20
          • 1970-01-01
          相关资源
          最近更新 更多