如果带有htmlAttributes的新EditorFor不适合你,我发现这是:
public bool BoolTest { get; set; }
public string StringTest { get; set; }
public int IntTest { get; set; }
public decimal DecimalTest { get; set; }
public float FloatTest { get; set; }
public char CharTest { get; set; }
public DateTime DateTimeTest { get; set; }
public TimeSpan TimeSpanTest { get; set; }
// WORKS
@Html.EditorFor(model => model.BoolTest, new { htmlAttributes = new { @class = "form-control bool" } })
// DOESN'T WORK!
@Html.EditorFor(model => model.StringTest, new { htmlAttributes = new { @class = "form-control string" } })
// WORKS
@Html.EditorFor(model => model.IntTest, new { htmlAttributes = new { @class = "form-control int" } })
// DOESN'T WORK!
@Html.EditorFor(model => model.DecimalTest, new { htmlAttributes = new { @class = "form-control decimal" } })
// DOESN'T WORK!
@Html.EditorFor(model => model.FloatTest, new { htmlAttributes = new { @class = "form-control float" } })
// DOESN'T WORK!
@Html.EditorFor(model => model.CharTest, new { htmlAttributes = new { @class = "form-control char" } })
// DOESN'T WORK!
@Html.EditorFor(model => model.DateTimeTest, new { htmlAttributes = new { @class = "form-control DateTime" } })
// DOESN'T WORK!
@Html.EditorFor(model => model.TimeSpanTest, new { htmlAttributes = new { @class = "form-control TimeSpan" } })
<小时/> 工作方式:使用按预期添加的其他htmlAttributes呈现输入。
DOESN&#39;工作方式:输入已呈现,但没有htmlAttributes传递到html。
<小时/> 结果HTML:
<input class="form-control bool check-box" data-val="true" data-val-required="The BoolTest field is required." id="BoolTest" name="BoolTest" type="checkbox" value="true">
<input name="BoolTest" type="hidden" value="false">
<input class="text-box single-line" id="StringTest" name="StringTest" placeholder="" type="text" value="">
<input class="form-control int text-box single-line valid" data-val="true" data-val-number="The field IntTest must be a number." data-val-required="The IntTest field is required." id="IntTest" name="IntTest" type="number" value="0">
<input class="text-box single-line" data-val="true" data-val-number="The field DecimalTest must be a number." data-val-required="The DecimalTest field is required." id="DecimalTest" name="DecimalTest" type="text" value="0.00">
<input class="text-box single-line" data-val="true" data-val-number="The field FloatTest must be a number." data-val-required="The FloatTest field is required." id="FloatTest" name="FloatTest" placeholder="" type="text" value="0">
<input class="text-box single-line" data-val="true" data-val-required="The CharTest field is required." id="CharTest" name="CharTest" placeholder="" type="text" value="�">
<input class="datefield" data-val="true" data-val-date="The field DateTimeTest must be a date." data-val-required="The DateTimeTest field is required." id="DateTimeTest" name="DateTimeTest" type="text" value="1/1/0001">
<input class="text-box single-line" data-val="true" data-val-required="The TimeSpanTest field is required." id="TimeSpanTest" name="TimeSpanTest" placeholder="" type="text" value="00:00:00">
有人找到了解决方法吗?我应该在哪里提交错误? (如果有人确认它不是我的机器,将会很棒)
答案 0 :(得分:2)
发现我有较旧的EditorTemplates用于那些没有考虑到新htmlAttributes的原语。
留下问题&#39;在这里,如果有人发现自己处于相同的情况。