I am trying to display a summary error message on a form as well as property level errors.
我试图在窗体上显示摘要错误消息以及属性级别错误。
The property errors get rendered using html.validationmessagefor(model =>...)
which works fine.
使用html.validationmessagefor(model => ...)呈现属性错误,它可以正常工作。
But when there is one or more validation errors, I want html.ValidationSummary(true)
to display the message "Your form is missing some details - see below".
但是当有一个或多个验证错误时,我希望html.ValidationSummary(true)显示消息“你的表单缺少一些细节 - 见下文”。
There also might be some server side validation which will occur post submit and will be added with ModelState.AddError
.
也可能会在提交后发生一些服务器端验证,并将与ModelState.AddError一起添加。
How can I get a class level dataattribute (presumably using [AttributeUsage(AttributeTargets.Class)])
to display in the summary validation using unobtrusive validation?
如何使用不显眼的验证获得类级别数据属性(可能使用[AttributeUsage(AttributeTargets.Class)])在摘要验证中显示?
1 个解决方案
#1
0
Is this what you are looking for:
这是你想要的:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.ValidationSummary("Errors:")
<div>
@Html.EditorFor(model => model.PathToExcel)
@Html.ValidationMessageFor(model => model.PathToExcel)
</div>
<div>
<input type="submit" value="Load" />
</div>
}
this uses 2 ValidationSummary's, one to fill the ValidationMessageFor-fields and one to use a Summary. Summary only works after Submitting.
这使用2个ValidationSummary,一个用于填充ValidationMessageFor-fields,另一个用于使用Summary。摘要仅在提交后有效。
#1
0
Is this what you are looking for:
这是你想要的:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.ValidationSummary("Errors:")
<div>
@Html.EditorFor(model => model.PathToExcel)
@Html.ValidationMessageFor(model => model.PathToExcel)
</div>
<div>
<input type="submit" value="Load" />
</div>
}
this uses 2 ValidationSummary's, one to fill the ValidationMessageFor-fields and one to use a Summary. Summary only works after Submitting.
这使用2个ValidationSummary,一个用于填充ValidationMessageFor-fields,另一个用于使用Summary。摘要仅在提交后有效。