我有以下代码:
@Html.ValidationSummary(false)
@Html.ValidationSummary(true, "xxx")
@using (Ajax.BeginForm(
action,
"Menus",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success
}, new { @id = "menuForm" }))
{
<dl>
<dt>@Html.LabelFor(model => model.Order)</dt>
<dd>@Html.TextBoxFor(model => model.Order)</dd>
<dd>@Html.ValidationMessageFor(model => model.Order)</dd>
</dl>
当我输入 999 的订单值时,我立即得到客户端验证,在订单文本框之后显示一条错误消息。但是,Html.ValidationSummary 区域中没有显示任何内容。是否可以将其与客户端验证一起使用?
这是我的模型:
public class Menu
{
[Range(0, 99, ErrorMessage = "{0} must be between {1} and {2}")]
[DisplayName("Order")]
public int Order { get; set; }
我的网络配置:
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
最佳答案
我不是 100% 确定,但我可以在 MVC 3 默认应用程序中找到的验证摘要在表单中。也许是因为您的验证摘要位于表单之外,它们不会得到更新。
当您在表单内移动验证摘要时会发生什么?
从:
@Html.ValidationSummary(false)
@Html.ValidationSummary(true, "xxx")
@using (Ajax.BeginForm(
action,
"Menus",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success
}, new { @id = "menuForm" }))
{
<dl>
<dt>@Html.LabelFor(model => model.Order)</dt>
<dd>@Html.TextBoxFor(model => model.Order)</dd>
<dd>@Html.ValidationMessageFor(model => model.Order)</dd>
</dl>
到:
@using (Ajax.BeginForm(
action,
"Menus",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success
}, new { @id = "menuForm" }))
{
@Html.ValidationSummary(false)
@Html.ValidationSummary(true, "xxx")
<dl>
<dt>@Html.LabelFor(model => model.Order)</dt>
<dd>@Html.TextBoxFor(model => model.Order)</dd>
<dd>@Html.ValidationMessageFor(model => model.Order)</dd>
</dl>
关于asp.net-mvc - @Html.ValidationSummary 是否适用于 MVC3 或 MVC4 中的客户端验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9210197/