简体   繁体   English

将消息写入验证摘要

[英]Write message to validation summary

I have a Razor Pages application (ASP.NET Core).我有一个 Razor Pages 应用程序(ASP.NET Core)。

Is there a way to write a message to the validation summary from JavaScript?有没有办法从 JavaScript 向验证摘要写入消息? And have it appear formatted (red, etc.)?它是否已格式化(红色等)?

The validation summary tag helper adds a CSS class to the div where the validation summary is rendered: validation-summary-errors .验证摘要标签助手向呈现验证摘要的 div 添加一个 CSS 类: validation-summary-errors You can use that (or any other selector you add to the div) to get a reference to the div in JavaScript:您可以使用它(或添加到 div 的任何其他选择器)在 JavaScript 中获取对 div 的引用:

var summary = document.querySelector('.validation-summary-errors');
summary.innerHTML = "<p style='color:red;'>Oops!</p>";

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

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