views:

54

answers:

4

I remember once seeing a project a guy did where he write something like this in some language with json like strings which created pretty good html. Is there something like it i can use for C# or .NET

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

If you are using ASP.NET, there is the HTML Agility pack.

It has many helpers to deal with HTML. It will not be exactly as the format you are describing, but is still easier than dealing with raw HTML.

From the website:

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).

Oded
A: 

If you take a look at ASP.NET MVC there are a lot of built in html helper methods there, is that the kind of thing you mean?

http://www.asp.net/mvc

Steve Haigh
A: 

Not exactly the answer but there is the TagBuilder in Asp.Net MVC.

Maxwell Troy Milton King
+1  A: 

While it doesn't match the code sample in your question, but maybe you are looking for a templating language like NHaml? Here's a short NHaml example:

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

Is equivalent to:

<h1>List of products</h1>
<ul>
    <% foreach (var product in products) %>
        <li>
            <%= product.Name %>
        </li>
    <% } %>
</ul>
Jørn Schou-Rode