开发者

how to append some error messages on xval validation summary through javascript in MVC?

how to append error messages on validation summary through javascript. i have added a validation summary, click on check button need to validate the credit card and retrieve the information back to the user, if the ca开发者_如何学运维rd is invalid i need to display that message in the validation summary. how can i do that? is there any way to programatically add the error messages to the validation summary using javascript?


First of all, you need to express your question better...

As far as I understand, you make AJAX call and if it fails you need to update the validation summary. Solution: use jQuery.

More details: Validation summary is rendered into the element with class "validation-summary-errors" - like this:

<ul class="validation-summary-errors">
   <li>First Name too long</li>
   <li>Invalid Email Address</li>
</ul>

So to update it you need to append a new li item to it. Here's how you do using jQuery:

$(".validation-summary-errors").append(
    "<li>" + "Your card is not valid" + "</li>");

Now, where to call the above code depends on how you check the credit card - jquery, ms ajax, etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜