One other useful (and extremely powerful) feature we are
enabling with Razor is the ability to pass “inline template” parameters to
helper methods. These “inline templates” can contain both HTML and code,
and can be invoked on-demand by helper methods.
Below is an example of this feature in action using a “Grid”
HTML Helper that renders a DataGrid to the client:
The Grid.Render() method call above is C#. We are using
the new C# named parameter syntax to pass strongly-typed arguments
to the Grid.Render method - which means we get full statement
completion/intellisense and compile-time checking for the above syntax.
The “format” parameter we are passing when defining columns
is an “inline template” – which contains both custom html and code, and which
we can use to customize the format of the data. What is powerful about
this is that the Grid helper can invoke our inline template as a delegate
method, and invoke it as needed and as many times as it wants. In the scenario
above it will call it each time it renders a row in the grid – and pass in the
“item” that our template can use to display the appropriate response.
This capability will enable much richer HTML helper methods
to be developed. You’ll be able to implement them using both a code
approach (like the way you build extension methods today) as well as using the
declarative @helper {} approach.