'asp-validation-summary div displaying even without errors

This is my page. My page

The red box is the validation summary div

I use taghelpers and the div looks like this

<div asp-validation-summary="ValidationSummary.All" class="validation-summary alert alert-danger"></div>

Is there any way to only display this div if the user has pressed the button ?

I've tried hiding it and then showing it using jquery when the button is pushed, but because the page reloads it stays hidden even after.

My page is in ASP.Net 5 MVC 6.



Solution 1:[1]

wrapping it in an if statement fixed it

@if (!ViewData.ModelState.IsValid)
{
<div asp-validation-summary="ValidationSummary.All" class="validation-summary alert alert-danger"></div>
}

Solution 2:[2]

Use CSS class .validation-summary-valid

.validation-summary-valid {  
    display: none;  
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3621898
Solution 2 Kappa