Expression Block

An expression block is similar to a Code Block, except that its main purpose is to produce output.

A code block starts with the characters <%= and ends with the characters %>. As you can see, it looks similar to a code block, but contains an equal sign as the very first character inside the block.

The contents of the block will be evaluated as an expression, and the result will be output to the template output, after converting it to a string using the ToString method of whatever value it ends up as.


The current date and time is: <%= DateTime.Now %>.

You could write the above example using normal code blocks as follows:

The current date and time is: <% generatedTemplateOutput.Append(DateTime.Now); %>.

Last edited Jan 20, 2011 at 10:46 PM by lassevk, version 1


No comments yet.