You'd have to provide your own extension method for Html.LabelFor()
(and the like for that matter) that would take into consideration tool tip attribute. It doesn't necessarily have to be derived from data annotations, since it's going to be custom handled.
You could of course inherit from DisplayName
and then use that one. What you'd get doing this? You'd only have to provide a single attribute like DisplayNameWithTooltip
that would then work as DisplayName
and you'll use it in our code to get tooltip as well.
Additional edit
If your tooltips should be implemented by using HTML element's title
attribute, then I didn't mean to use some special string syntax in DisplayName
attribute but rather create a new attribute class that inherit DisplayNameAttribute
:
public class DisplayNameWithTooltipAttribute: DisplayNameAttribute
{
public string Tooltip { get; private set; }
public DisplayNameWithTooltipAttribute(string displayName, string tooltip) : base(displayName)
{
this.Tooltip = tooltip;
}
...
}
And then use your custom attribute:
[DisplayNameWithTooltip("Some display name", "Some tooltip")]
public ActionResult SetSomething(SomeObj val) { ... }
This way you won't have to parse your strings and other code will be able to use it as well since it inherits from DisplayName
(because code probably uses calls IsAssignableFrom
calls and similar).