Contents tagged with EditorFor

  • Subtle difference between Html.TextAreaFor and Html.EditorFor

    Hello everybody,

    today I want to document one gotcha related to difference between Html.TextAreaFor and Html.EditorFor.

    Recently I've had a requirement to add hint text to text fields. In Html world there are two ways to create input field which accepts text: <input type="text" /> and <textarea>some text </textarea>. In MVC world you can create those tags with help of Html.TextAreaFor and Html.EditorFor.

    I've had challenges with trying to apply attribute placeholder to TextAreaFor. EditorFor was pretty simplte to google and find:

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

    But finally after a research I've … more