You cannot use Html.editorfor () because you need to specify HTML attributes for the generated control
@Html. textboxfor (model = model. StartDate, new {Value = String.Format ("{0:yyyy-mm-dd}", Model.startdate)})
@Html. textboxfor (model = model. StartDate, "{0:YYYY-MM-DD}", new {@class = "m-wrap small", @readonly = "true"})
@Html. textboxfor (model = model. StartDate, new {Value = Model.StartDate.ToString ("Yyyy-mm-dd")})
The above three types are correct, there are two points to note:
1. Force change the Control Value property, note that this value cannot be lowercase;
2. Note that model is the attribute of system.web.mvc.webviewpage<tmodel>, which differs from the model in LAMDA expression.
The definition of model is public TModel model {get;}
Webviewpage<tmodel> inherit from Webviewpage;
3, Modelstate.clear (); Empties the value in the model, Modelstate.remove ("XXX"); empties a value.
Example:
<span> operating Time:</span>
From @Html. textboxfor (model = model. Query.begintime, new {Value = Model.Query.BeginTime.ToString ("Yyyy-mm-dd"), @class = "Wdate", OnClick = "Wdatepicker ({da TEFMT: ' Yyyy-mm-dd '}); ", style =" width:100px; "})
To @Html. textboxfor (model = model. Query.endtime, new {Value = Model.Query.EndTime.ToString ("Yyyy-mm-dd"), @class = "Wdate", OnClick = "Wdatepicker ({DATEFM T: ' Yyyy-mm-dd '}); ", style =" width:100px; "})
MVC @Html. Textboxfor formatting