Asp.net mvc MVC-将EditorTemplate与EditorForModel一起使用时不会触发模型验证

Asp.net mvc MVC-将EditorTemplate与EditorForModel一起使用时不会触发模型验证,asp.net-mvc,mvc-editor-templates,html.beginform,Asp.net Mvc,Mvc Editor Templates,Html.beginform,我正在为Html.EditorForModel()使用EditorTemplate 在不使用EditorTemplate的情况下使用时,验证有效。 如果没有EditorTemplate,验证将不起作用 这是我的表格: <div style="padding-top: 20px;"> @using (Html.BeginForm()) { @Html.EditorForModel() } </div> @使用(Html.BeginFor

我正在为
Html.EditorForModel()使用
EditorTemplate
在不使用
EditorTemplate
的情况下使用时,验证有效。 如果没有
EditorTemplate
,验证将不起作用

这是我的表格:

<div style="padding-top: 20px;">
   @using (Html.BeginForm())
   {
        @Html.EditorForModel()
   }
</div>

@使用(Html.BeginForm())
{
@Html.EditorForModel()
}
这是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>

@EditorFor(x=>x.UserName,new{htmlAttributes=new{placeholder=“UserName”})
@EditorFor(x=>x.Password,new{htmlAttributes=new{placeholder=“Password”})
这是
html
生成的:


我缺少什么?

我通过为这两个属性添加
Html.ValidationMessageFor
解决了这个问题


@Html.ValidationMessageFor(x=>x.UserName,”,new{@class=“text danger”})

纯粹出于好奇,您使用带有EditorTemplate的EditorForModel而不是直接在表单中插入EditorTemplate的内容,这有什么原因吗?没有原因。只是为了自我教育:)好吧,很公平!