r-aghaei / HtmlUsingRuntimeT4

An example showing how to generate html dynamically at run-time based on a model using Run-time T4 templates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generating Html using T4 Run-time Templates

Sometimes you want to create a simple text report to print. In these cases generating html output is really useful. Also sometimes you may need to generate some html content at runtime to include in an email.

As an option to create html templates easlily, to make rendering logic and mixing html tags and data simpler, you can use Run-time Text Templates. This way, you can use the t4 template as a view renderer which accepts a model (your data) and render the output.

Then you can pass data to the html template and render the report simply. If you are going to show it in a form, you can assign the output string to a DocumentText property of a WebBrowser and call its Print method to print the document or ShowPrintPreviewDialog to show print preview dialog:

runtime html generation using t4 runtime templates

About

An example showing how to generate html dynamically at run-time based on a model using Run-time T4 templates.


Languages

Language:C# 100.0%