Model Cs
Model Cs
Title%>
Introduction
You can specify a view model when you create a document:
The specified model will be used for every generated document. If you want to generate the same
document multiple times but with different models, specify a model when calling Generate:
document.Generate(documentPath, model);
The assembly containing the model will automatically be referenced. Also, the namespace of the model
will be imported automatically.
From the view (i.e. this Word document), the model can be accessed through the Model property. This
property is strongly typed, so you can access all fields/properties/methods without casting. In this
example, the model is of type Model.Models.MyViewModel and looks like this:
Because we’ll be using the extension method MyToString, we need to import its namespace using the
Import directive.
<% } %>
<% } %>
It’s also possible to generate paragraphs instead of table rows, like this:
Country
Name: <%= c.Name %>
Population: <%= c.Population / 1000 %> K
Date proclaimed: <%= c.DateProclaimed.MyToString() %>
<% } %>
<% } %>
Document generated on <%= Model.Date %> in CLR runtime version <%= Environment.Version %>.