I want to know if Html.ValidationSummary is present in code. The tag div class="validation-summary-valid" is not present in html if Html.ValidationSummary has a parameter of true. i.e. Html.ValidationSummary(true), the result, there’s no reliable way to know in jquery if Html.ValidationSummary is in code.
Is there a property that says so? The presence or absence of Html.ValidationSummary
[EDIT: clarification]
Putting Html.ValidationSummary with a parameter of true:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<b>Hello</b>
,and not putting any Html.ValidationSummary:
@using (Html.BeginForm()) {
<b>Hello</b>
,both code yields the same HTML(View Page Source):
<b>Hello</b>
That being so, there’s no reliable way from jQuery to know if Html.ValidationSummary is present or not in the code
It is happening because
ValidationSummaryhelper does not return empty<div class="validation-summary-errors"/>if there is no errors (whenViewData.ModelState.IsValidreturnstrue). In such case you need to have customValidationSummarywhich fixing that:This custom
ValidationSummaryhelper will generate emptyvalidation-summary-errors diveven if there is was no errors, other words<div class="validation-summary-errors"/>would be present in your html every time, like you want.