Reputation: 4882
I need two different DisplayTemplates for the same ViewModel. One is for displaying the ViewModel on a regular page, and the other is for displaying the ViewModel on a print-friendly page. My ViewModels all derive from a base model, and DisplayFor figures out which DisplayTemplate to use when i give it a List of the base model.
As i can understand, DisplayFor looks for a filename in the DisplayTemplates folder that equals the type of the model it has been passed. I cannot have multiple files with the same name.
How can i solve this?
Thanks!
Upvotes: 1
Views: 270
Reputation: 10924
There is an overload of DisplayFor
which allows you to pass the template name. If you name the print template by adding Print
after the model name, you can then call the print template like so:
@Html.DisplayFor(x => x.MyModel, "MyModelPrint")
Upvotes: 6