I have an MVC view that is using Bootstrap styles. I want to use "@Html.EditorFor" rather than "@HtmlTextBoxFor". Why doesn't EditorFor work out that it needs to be a textbox and then end up with the same result and TextBoxFor??
My reason for asking is that my next field will be a date and want to use EditorFor and with the DataType data annotation it will display a date picker.
Below is screenshot and view code and the Forename is EditorFor whilst the Surname is (the preferred format) TextBoxFor.
<div class="form-group">
@Html.LabelFor(m => m.Title, new { @class = "control-label" })
@Html.DropDownListFor(m => m.Title, new SelectList((IEnumerable)@ViewData["Titles"]), new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Forenames, new { @class = "control-label" })
@Html.ValidationMessageFor(m => m.Forenames)
@Html.EditorFor(m => m.Forenames, new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Surname, new { @class = "control-label" })
@Html.ValidationMessageFor(m => m.Surname)
@Html.TextBoxFor(m => m.Surname, new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.DateOfBirth, new { @class = "control-label" })
@Html.ValidationMessageFor(m => m.DateOfBirth)
@Html.EditorFor(m => m.DateOfBirth, new { @class = "form-control" })
</div>
EditorFor
(which you cant do unless your using MVC5.2 or a customEditorTemplate
). You can always use the browsers datepicker implementation using@Html.TextBoxFor(...., new { type = "date" })
– user3559349EditorFor
so just use@TextBoxFor()
(or you can create anEditorTemplate
or custom html helper as explained in this answer) – user3559349