How can I use placeholder attribute with Html.EditorFor? How can I use placeholder attribute with Html.EditorFor? asp.net asp.net

How can I use placeholder attribute with Html.EditorFor?


Upgrade to MVC 5.1 and you can use HTML attributes in EditorFor:

@Html.EditorFor(m => m.variable, new { htmlAttributes = new { placeholder = "Your Placeholder Text" } })

http://www.asp.net/mvc/overview/releases/mvc51-release-notes


 @Html.EditorFor(model => model.members_ssn, new { htmlAttributes = new { @class = "form-control", placeholder = "Your Example Here" } })


This works for MVC 5.

In my case i was looking to set the placeholder from the model metadata, like this:

@Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.name) } })