I need this exact functionality, but I did not want to get EditorFor and change all my EditorFor to something else (I have a lot of pages :)).
For this, I simply created an EditorTemplate for String (you can do this for other types if you need it).
Based on my model properties, which I use DisplayName , like this:
[DisplayName("Client Name")] public string ClientName { get; set; }
The template was simple:
@model string @Html.TextBoxFor(m => m, new { @placeholder = ViewData.ModelMetadata.DisplayName })
And then my calling code remained the same:
@Html.EditorFor(m => m.FirstName)
Alternatively, you can use this work for non-HTML5 browsers with this exact code. All I did was add a script link to this great jQuery plugin poster , and all my placeholders even work in IE6 (!!!!).
mattytommo
source share