A technical blog about programming and technology.

Friday, December 21, 2007

Generating html with Xlinq?

As web developers we have, at some point in our careers generated html on the server.  It always gets messy especially when your are generating a table from data. Its always done with messy strings! What about setting attributes...   string row = "<td class=\"name\">" + value + "</td>" .. what a pain.
Xlinq is new in .NET 3.5 (The X stands for XML), you can read more about it here. I found(i think) a much better way to generate html on the server using asp.net. I needed to make an ajax call to the server that returned a filtered and paged table based on the parameters I passed.

Here is a screen shot of what the code looked like:

image

And generating the rows of the table:

image

The helper methods, Html.AsLink creates html markup("<a href...") as an XElement otherwise the special characters are escaped.

Pretty neat huh?

No comments: