asp.net mvc 3 验证摘要未通过不引人注目的验证显示
我在让 asp.net MVC 客户端验证按照我想要的方式工作时遇到问题。
我基本上可以正常工作,但是,在用户单击提交按钮之前,验证摘要不会显示,即使各个输入被突出显示为无效,因为用户在表单中进行了选项卡/单击等操作。这一切都发生在客户端。
我本以为一旦发现输入字段无效,就会显示验证摘要。
这是设计使然吗?有什么办法可以解决这个问题,因为我希望在发现其中一个输入字段无效时立即显示验证摘要。
我的代码基本上是,
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
...
@using (Html.BeginForm())
{
@Html.ValidationSummary(false)
@Html.EditorFor(model => model);
...
我的 _Layout.cshtml
引用 jquery-1.4.4.min.js
。
I'm having problems getting the asp.net MVC client-side validation to work how I want it.
I have it basically working, however, the validation summary is not displayed until the user clicks the submit button, even though the individual inputs are being highlighted as invalid as the user tabs/clicks etc their way through the form. This is all happening client-side.
I would have thought the that the validation summary would be displayed as soon as an input field was discovered that was invalid.
Is this behaviour by design? Is there any way around it, as I would like the validation summary to be displayed as soon as it is discovered that one of the input fields is invalid.
My code is basically,
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
...
@using (Html.BeginForm())
{
@Html.ValidationSummary(false)
@Html.EditorFor(model => model);
...
And my _Layout.cshtml
references jquery-1.4.4.min.js
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用了 Torbjörn Nomells 答案的一个版本,
除了这里,我将 ResetSummary 挂在验证器对象上
,然后将其调用更改为
I used a version of Torbjörn Nomells answer
Except here I hang resetSummary off the validator object
Then change calling it to
您可以在 onready 中设置更频繁地触发验证摘要:
这是上面使用的 ResetSummary:
You can setup the validation summary to be triggered a lot more often, in onready:
Here's the resetSummary used above:
我在这里有一个类似的问题: 如何在验证摘要中显示 MVC 3 客户端验证结果,但 Darin 建议的解决方案似乎并没有按照我(可能还有您)想要的方式工作。
I have a similar question open here: How to display MVC 3 client side validation results in validation summary but the suggested solution by Darin does not seem to work the way I (and probably you) want it to.