I encounter annoying binding behavior to bind DateTime to a text field that is disabled. It always returns null.
Does my model have a DateTime? Property StartDate ... I also tried only DateTime StartDate (without '?').
I tried the following:
Attempt # 1:
<%: Html.TextBoxFor(model => model.StartDate, new { @disabled="true" })%>
Attempt number 2:
<%: Html.EditorFor(model => model.StartDate, "DateDisabled")%>
where DateDisabled is a partial view defined as follows:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
<%: Html.TextBox("", Model.HasValue ? Model.Value.ToShortDateString() : "", new { @class = "text-box-short-disabled", @disabled = "true" })%>
All my attempts return a null value. Did I miss something? Or a workaround?
source
share