Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update:</strong></p> <p>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</p> <hr> <p>Interesting question. I would like to see an answer to this using attributes, but here are two methods I can think of:</p> <p><strong>Add an extension method to your objects</strong> This would require alot of repetitive code.</p> <pre><code>public static string GetTitle(this YourObject obj) { return "Title for object"; } </code></pre> <p><strong>Html Helper extension method</strong></p> <p>You would store the object titles in this helper method.</p> <pre><code>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; } } </code></pre> <p>To call this method:</p> <pre><code>&lt;%= Html.GetObjectTitle(Model.GetType()) %&gt; </code></pre> <p>Or in your example:</p> <pre><code>&lt;%= Html.TextBox("PostalCode", Model.PostalCode, new { watermark = "Postal Code", title = Html.GetObjectTitle(Model.GetType()) })%&gt; </code></pre> <p>I prefer the 2nd method because you have a place to store all the titles and you would need to write less code. </p> <p>However, I think adding an attribute to the class and creating a means to get that attribute would work a bit better.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload