我有String
和DateTime?
的DisplayTemplates,如下所示:
@model String
@Html.TextBoxFor(m => Model, new { @class="read-only"})
@model DateTime?
@{
String modelValue = "";
if (Model.HasValue)
{
if (Model.Value != DateTime.MinValue)
{
modelValue = Model.Value.ToShortDateString();
}
}
}
@Html.TextBox("", modelValue, new { @class = "date-picker date-text read-only", @readonly="readonly" })
我这样做是因为当我使用帮助器DisplayFor
时,我更喜欢背景较暗的文本框,我喜欢在date-picker
类上标记以便稍后将这些字段转换为正确的日期选择器。 / p>
班级read-only
只定义背景颜色。在这个模型的摘录中,
[Editable(false)]
[Display(Name = "File Name")]
public string FileName { get; set; }
[Editable(false)]
[Display(Name = "File Report Date")]
public DateTime? FileReportDate { get; set; }
两个属性几乎完全相同,但String
的显示模板拒绝添加read-only
类,其中DateTime
的模板恰到好处。
为什么会有这样的差异,为什么我的显示模板不会在其内部input
元素中添加一个类?
ADDED:似乎根本没有使用String的模板。为什么会这样?