Search code examples
asp.net-mvc-3razordisplay-templates

MVC 3 Razor - Create DisplayTemplate for specific Property Name e.g. WebsiteUrl, IsActive


I have very strict naming conventions for my models and I am wondering if I can leverage this via display templates for common fields like - WebsiteUrl, IsActive, UpdateDate, InsertDate?

Is it possible to create a Display Template based on a property's name?

EDIT:

I am aware that I can achieve this using something like this:

@Html.DisplayFor(model => model.Farmer.WebsiteUrl, "WebsiteUrl")

I am just wondering if there is a more strongly typed way of doing it.


Solution

  • you can use the UIHint("") attribute on your models, the name is the name for the file within your shared/EditorTemplates folder. i do this for things like upload box, jquery datepicker, WYSIWYG editor etc