I am creating an attribute that I will use to provide additional information about the unit of measure of a property in an MVC 3 ViewModel. This follows me asking about the best way to accomplish this.
I have created a UnitOfMeasure attribute that passes additional information to the string template via the AdditionalValues metadata. Ideally I would like to create a Editor Template for UnitOfMeasure rather than adding it to the string editor template.
Is there anyway to tell a custom metadata provider to change the selected template? Effectively if it sees the UnitOfMeasure attribute on a property then I would like to also add UiHint(“UnitOfMeasure”) automaticallly behind the scenes. That way I would not have to add code for my UnitOfMeasure helper in the string editor template.
I should note that I don’t want to use UiHint control parameters (unless it is the only option)
Thanks
You could have your custom attribute derive from UIHint:
and then:
or:
and in both case in the view:
in the first case, obviously the
~/Views/Shared/EditorTemplates/foo.cshtmlcustom template will be used whereas in the second the default string template.