0

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.

Rob
  • 10,004
  • 5
  • 61
  • 91

1 Answers1

1

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

davethecoder
  • 3,856
  • 4
  • 35
  • 66
  • http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx – davethecoder Aug 20 '11 at 12:08
  • Oh nice!! thanks for this :-) not quite what I wanted as it requires still more meta data decorating but it's better than nothing. And I will probably be grateful doing it this way as doing it the way I wanted to will end up with me coming unstuck when I don't want a particular property to be assigned to a common label. – Rob Aug 21 '11 at 13:29