-1

I want to use placeholder in @Html.EditorFor for text in mvc. I tried many of things even search in google but whatever the answer I got that not work. I surprised...!!!. And finally I ask in question.

My lastest code for placeholder is

@Html.EditorFor(model => model.ToEmail, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Your EmailID...!!!" } })

This code also not work.

Thank You.

s.k.Soni
  • 1,139
  • 1
  • 19
  • 37

2 Answers2

1

I had the same problem as yours, below code worked for me in my project:

@Html.EditorFor(model => model.ToEmail, new { htmlAttributes = new {placeholder = @Html.DisplayNameFor(m=>m.ToEmail) } })
0

If you need to add HTML attributes you should use @HTML.TextBoxFor instead of EditorFor and bind value from value attribute i.e.

 @Html.TextBoxFor(model => model.ToEmail, new {  @value = model.ToEmail, @class = "form-control", @placeholder = "Enter Your EmailID...!!!"  })
adiga
  • 34,372
  • 9
  • 61
  • 83
  • Never set the `value` attribute when using the `HtmlHelper` methods. –  Nov 18 '17 at 22:47