I want to create a display template for string properties only, and use default for all others.
I tried to make a string.cshtml in Views/Shared/DisplayTemplates with following contents:
@model string
@Html.TextBoxFor(m => m, new { @readonly = "readonly" })
I now have a problem when I try to open any view which uses DisplayFor(m => m.property), it shows error like: The model item passed into the dictionary is of type 'System.DateTime', but this dictionary requires a model item of type 'System.String'. or: The model item passed into the dictionary is of type 'System.Int64', but this dictionary requires a model item of type 'System.String'.
I know that I can solve this by adding display template for every type used, but I suppose that it is also possible to use "default" template for all types where custom template is not defined?
UPDATE After Darin's answer, I checked Brad's tutorial and changed template into:
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @readonly = "readonly" })
This is based on "default" template and works for all types.