Im using dotnet core MVC and am having issues with asp-validation-summary.
Validation is working at a field level using asp-validation-for however I am not getting anything showing up in the asp-validation-summary.
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
I have also tried
<div asp-validation-summary="All" class="text-danger"></div>
Any ideas what I am missing.
Done loads of searching and cant see solution to my problem
Thanks
ValidationSummary control Syntax : Now, Let's understand ValidationSummary control with an asp.net example. Step 1 – Open Visual Studio –> Create a new empty Web application. Step 2 – Create a new web form and design a web form as shown in below screen. Step 3 – Drag and drop ValidationSummary control from Toolbox.
Validation Message Tag Helper (asp-validation-for)It displays the error message for a single property of our Model. It can be achieved by asp-validation-for tag helper. It adds the data-valmsg-for="property name" attribute to the element which it carries for example span.
The ValidationSummary class is used to summarize the error messages from all validators on a Web page in a single location. You can summarize the error messages from a group of validators on a Web page by assigning the ValidationSummary control to a validation group by setting the ValidationGroup property.
Also you can include jquery script for validation tag-helper
<form asp-controller="home" asp-action="CreatePoll" method="post" class="mt-3">
<div class="validation" asp-validation-summary="All"></div>
<div class="form-group">
<label asp-for="Name">Name of the Poll:</label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Create</button>
</form>
@section scripts{
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With