Update:
You could just create a new class property for each of your object named "Title" or "Hint" and add the appropriate string value to them. Then get that property with MyObject.Title
Interesting question. I would like to see an answer to this using attributes, but here are two methods I can think of:
Add an extension method to your objects
This would require alot of repetitive code.
public static string GetTitle(this YourObject obj)
{
return "Title for object";
}
Html Helper extension method
You would store the object titles in this helper method.
public static string GetObjectTitle(this HtmlHelper html, string type)
{
switch(type)
{
case "Object1":
return "Title for object 1";
break;
case "Object2":
return "Title for object 2";
break;
default:
return "No titled specified for this object type";
break;
}
}
To call this method:
<%= Html.GetObjectTitle(Model.GetType()) %>
Or in your example:
<%= Html.TextBox("PostalCode", Model.PostalCode, new {
watermark = "Postal Code",
title = Html.GetObjectTitle(Model.GetType()) })%>
I prefer the 2nd method because you have a place to store all the titles and you would need to write less code.
However, I think adding an attribute to the class and creating a means to get that attribute would work a bit better.