user3953989
user3953989

Reputation: 1929

How to display client-side validation error without asp-validation-for?

I'm trying to customize the way the client-side validation is displayed on my form.

I don't want to use the asp-validation-for tags so they don't display with the control. I'd rather show these in the ValidationSummary control with the other errors or some other centralized place.

Is there a way to show the client-side model.field errors anywhere other than using a asp-validation-for tag?

Upvotes: 0

Views: 617

Answers (1)

Dimitris Maragkos
Dimitris Maragkos

Reputation: 11342

Use validation summary tag helper with attribute asp-validation-summary="All"

<form asp-controller="Demo" asp-action="RegisterValidation" method="post">
    <div asp-validation-summary="All"></div>
</form>

Ιt's important that the validation summary tag helper is placed inside the <form> tag!

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/working-with-forms?view=aspnetcore-6.0#the-validation-summary-tag-helper

Upvotes: 2

Related Questions