我在页面上有2个验证表单。
<div id='LogOn' style="background-color: White;">
@using (Ajax.BeginForm("LogOnAjax", "Home", new AjaxOptions { UpdateTargetId = "LogOn", OnSuccess = "logInComplete" }))
{
//ITW2012Mobile.ViewModels.LogOnModel m = Model;
@Html.HiddenFor(model => model.IsLoggedIn)
@Html.HiddenFor(model => model.ReturnUrl)
<div>
@Html.ValidationSummary()
</div>
<div>
@Html.LabelFor(model => model.UserName)
@Html.EditorFor(model => model.UserName)
</div>
<div>
@Html.LabelFor(model => model.Password)
@Html.EditorFor(model => model.Password)
</div>
<div>
<input type="submit" value="Login" />
</div>
}
</div>
和
<fieldset>
@using (Html.BeginForm(Model.ActionMethod, Model.Controller))
{
@Html.ValidationSummary()
.....
<div class="display-label"> E-mail Address * </div>
<div class="display-field">
@Html.EditorFor(model => model.Username)
@Html.ValidationMessageFor(model => model.Username)
</div>
<div class="display-label"> Create Password * </div>
<div class="display-field">
@Html.PasswordFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>
<p>
<input type="submit" value="Create" />
</p>
}
</fieldset>
我如何标记ModelState.AddModelError
是表格的第一个,因为我在validation summary
的两个地方都看到同样的错误?
答案 0 :(得分:0)
如何标记ModelState.AddModelError用于表单的第一个
你做不到。
您可以做的是为每个表单属性而不是ValidationMessageFor
ValidationSummary