Write message to validation summary

165 Views Asked by At

I have a Razor Pages application (ASP.NET Core).

Is there a way to write a message to the validation summary from JavaScript? And have it appear formatted (red, etc.)?

1

There are 1 best solutions below

0
Mike Brind On

The validation summary tag helper adds a CSS class to the div where the validation summary is rendered: 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:

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