Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As smnbss comments in Darin Dimitrov's answer, <code>Prompt</code> exists for exactly this purpose, so there is <strong>no need to create a custom attribute</strong>. From the the documentation:</p> <blockquote> <p>Gets or sets a value that will be used to set the watermark for prompts in the UI.</p> </blockquote> <p>To use it, just decorate your view model's property like so:</p> <pre><code>[Display(Prompt = "numbers only")] public int Age { get; set; } </code></pre> <p>This text is then conveniently placed in <code>ModelMetadata.Watermark</code>. Out of the box, the default template in MVC 3 ignores the <code>Watermark</code> property, but making it work is really simple. All you need to do is tweaking the default string template, to tell MVC how to render it. Just edit String.cshtml, like Darin does, except that rather than getting the watermark from <code>ModelMetadata.AdditionalValues</code>, you get it straight from <code>ModelMetadata.Watermark</code>:</p> <p>~/Views/Shared/EditorTemplates/String.cshtml:</p> <pre><code>@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "text-box single-line", placeholder = ViewData.ModelMetadata.Watermark }) </code></pre> <p>And that is it.</p> <p>As you can see, the key to make everything work is the <code>placeholder = ViewData.ModelMetadata.Watermark</code> bit.</p> <p>If you also want to enable watermarking for multi-line textboxes (textareas), you do the same for MultilineText.cshtml:</p> <p>~/Views/Shared/EditorTemplates/MultilineText.cshtml:</p> <pre><code>@Html.TextArea("", ViewData.TemplateInfo.FormattedModelValue.ToString(), 0, 0, new { @class = "text-box multi-line", placeholder = ViewData.ModelMetadata.Watermark }) </code></pre>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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