开发者

ASP.NET MVC ValidationSummary For Client Side Validation

Our server side validation (via data annotations) is working great and posts the errors in our ValidationSummary h开发者_JAVA百科ow we like it. The client side validation also works, however the errors display to the right of the control and the validation summary never displays. Is there an easy way to make the client validation display to look like that of server side validation display?


If you're talking about using ASP.NET MVC 2 Preview 2 or any other generated client side validation that uses the jQuery Validation library, you should check out errorLabelContainer and errorContainer in the documentation for jQuery Validation library.

That should get your client side validation looking more like the server side validation summary. :-)

HTHs,
Charles

Ps. If you can't alter the $('myForm').Validate()'s options, just use the $.validator.setDefaults(); approach. Although you could get into trouble with more than one form / validation summary on a page.


Not sure if it's good practice to use with ASP.NET MVC 2, but with xVal cliend side validation summary is easy to do.

<div id="validationSummary">
        <%= Html.ValidationSummary("Please fix the following problems:") %>
</div>

<%= Html.ClientSideValidation("booking", typeof(Booking))
        .UseValidationSummary("validationSummary") %>


You should verify that for the model object being validated that the .Error property from the IDataErrorInfo interface is not String.Empty. This might cause the behaviour you seem to be having.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜