Does MVC4
by default support placeholders
for generated input fields? I didn't found anything so I am trying to implement my own but unfortunately Prompt = "E-Mail"
is not passed to ViewData.ModelMetadata.Watermark
while generating control. Why?
Model
public class LogOnModel
{
[Required]
[Display(Name = "E-Mail", Prompt = "E-Mail")]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
}
@Html.TextBoxFor(m => m.Email, new { placeholder = ViewData.ModelMetadata.Watermark })
I get html code where placeholder
tag do not has any text
<input data-val="true" data-val-regex="Please enter a valid e-mail address" data-val-required="The E-Mail field is required." id="Email" name="Email" placeholder="" type="text" value="" class="valid">
See Question&Answers more detail:os