Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp-validation-summary not showing, field validation working

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

like image 611
Mike U Avatar asked Jun 14 '17 21:06

Mike U


People also ask

How can validate summary in asp net?

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.

How does ASP validation for work?

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.

What is the purpose of validation summary control in asp net?

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.


1 Answers

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>
    }
like image 109
Павел Голованов Avatar answered Sep 29 '22 03:09

Павел Голованов