如何在 MVC 中通过 javascript 在 xval 验证摘要上附加一些错误消息?

发布于 2024-08-08 20:53:29 字数 141 浏览 7 评论 0原文

如何通过 javascript 在验证摘要上附加错误消息。 我添加了验证摘要,单击检查按钮需要验证信用卡并将信息检索回用户,如果该卡无效,我需要在验证摘要中显示该消息。 我怎样才能做到这一点?有没有办法使用 javascript 以编程方式将错误消息添加到验证摘要中?

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 card 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好多鱼好多余 2024-08-15 20:53:29

首先,您需要更好地表达您的问题...

据我了解,您进行 AJAX 调用,如果失败,您需要更新验证摘要。解决方案:使用jQuery。

更多详情:
验证摘要被渲染到具有“validation-summary-errors”类的元素中 - 像这样:

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

因此要更新它,您需要向其附加一个新的 li 项。以下是使用 jQuery 的方法:

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

现在,在哪里调用上述代码取决于您检查信用卡的方式 - jquery、ms ajax 等。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文