I am in the initial phase of leaning web app development in MVC and having few questions related to below code -
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }
<div class="form-group">
@{ Html.Html5DateRenderingMode = Html5DateRenderingMode.Rfc3339; }
@Html.LabelFor(emp => emp.StartDate)
@Html.TextBoxFor(emp => emp.StartDate, new { @class = "form-control" })
@Html.EditorFor(emp => emp.StartDate, new { htmlAttributes = new { @class = "form-control" } })
</div>
Rendered as
I understand that TextBoxFor is rendered as type="text"
and EditorFor as type="datetime"
Questions -
1. Why TextBoxFor and EditorFor displays dates differently -
Does Html5DateRenderingMode is only applicable to input type="datetime"?
2. Why controls are rendered differently? I noticed that EditorFor which is rendered as type="datetime" is displayed on full page length input box.
3. When do we use Html5DateRenderingMode in a real-life project?
4. I understand that EditorFor is a preferred approach as it looks at object meta information and decides what control should be rendered.
In what cases, we should prefer TextBoxFor over EditorFor?
Thank you!