我正在EditorTemplate
使用Html.EditorForModel()
在没有EditorTemplate
的情况下使用时,验证有效。
没有EditorTemplate
- 验证不起作用。
这是我的表格:
<div style="padding-top: 20px;">
@using (Html.BeginForm())
{
@Html.EditorForModel()
}
</div>
这是EditorTemplate:
<div style="margin: 0px auto; text-align: center; display: table;">
<table>
<tr>
<td>@Html.EditorFor(x => x.UserName, new { htmlAttributes = new { placeholder = "username" } })</td>
</tr>
<tr>
<td>@Html.EditorFor(x => x.Password, new { htmlAttributes = new { placeholder = "password" } })</td>
</tr>
<tr style="height:70px;">
<td><input type="submit" class="k-primary" value="Log In" /></td>
</tr>
</table>
</div>
我错过了什么?
答案 0 :(得分:1)
我通过为两个属性添加Html.ValidationMessageFor
来解决它
@Html.ValidationMessageFor(x => x.UserName,"", new { @class = "text-danger"})