简体   繁体   English

通过异步更新ValidationSummary-ASP.NET MVC

[英]Updating ValidationSummary Via Asynchronously - ASP.NET MVC

In my controller, if the modelstate is invalid 在我的控制器中,如果modelstate无效

if (!ModelState.IsValid)
      return View();

I'd like to update the ValidationMessage but not have to repost the View. 我想更新ValidationMessage,但不必重新发布视图。 Seems like a desirable concept with validation messages. 似乎是带有验证消息的理想概念。 I'm using DataAnnotations as well that uses <% Html.EnableClientValidation(); %> 我也在使用使用<% Html.EnableClientValidation(); %> DataAnnotations <% Html.EnableClientValidation(); %> <% Html.EnableClientValidation(); %> but it still posts to the controller and I have to perform this check. <% Html.EnableClientValidation(); %>但它仍发布到控制器,我必须执行此检查。 Any suggested implementations? 有建议的实现方式吗?

You need to return the view with the model. 您需要使用模型返回视图。

if (!ModelState.IsValid)
    return View("Create", m);

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. 不确定这是否有帮助,但是听起来好像您希望在存在错误的情况下在客户端显示ValidationSummary,而不必将表单提交给服务器。 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 http://geekswithblogs.net/stun/archive/2010/02/27/asp.net-mvc-client-side-validation-summary-with-jquery-validation-plugin.aspx

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM