通过异步更新 ValidationSummary - ASP.NET MVC
在我的控制器中,如果模型状态无效,
if (!ModelState.IsValid)
return View();
我想更新 ValidationMessage 但不必重新发布视图。似乎是一个带有验证消息的理想概念。我也在使用 DataAnnotations,它使用 <% Html.EnableClientValidation(); %>
但它仍然发布到控制器,我必须执行此检查。有什么建议的实现吗?
In my controller, if the modelstate is invalid
if (!ModelState.IsValid)
return View();
I'd like to update the ValidationMessage but not have to repost the View. Seems like a desirable concept with validation messages. I'm using DataAnnotations as well that uses <% Html.EnableClientValidation(); %>
but it still posts to the controller and I have to perform this check. Any suggested implementations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要返回带有模型的视图。
You need to return the view with the model.
不确定这是否有帮助,但听起来您希望在存在错误时在客户端显示 ValidationSummary,而不必将表单提交到服务器。我不久前遇到了这个问题,并按照这篇文章中概述的方式以一种有点尴尬的方式解决了它;
http://geekswithblogs.net/stun/archive/2010/02/27/asp.net-mvc-client-side-validation-summary-with-jquery-validation-plugin.aspx
希望这个有帮助!
Not sure if this will help, but it sounds like you want the ValidationSummary to be displayed client side when errors exist without having to submit the form to the server. I ran into this a while ago and solved it in somewhat of an awkward manner with what was outlined in this post;
http://geekswithblogs.net/stun/archive/2010/02/27/asp.net-mvc-client-side-validation-summary-with-jquery-validation-plugin.aspx
Hope this helps!