I am writing an mvc web app and I'm trying to check to see if there are any errors in the Html.ValidationSummary to determine if I need to display the div that handles the messages.
@if(Html.ValidationSummary() != null)
{
<div class="registration-val-summary">
<label class="registration-val-label">
Please correct the following issues with your registration:
</label>
@Html.ValidationSummary()
</div>
}
This is the error that I receive:
Unexpected "if" keyword after "@" character. Once inside code, you do not need to prefix constructs like "if" with "@".
From what I read in this post: Unexpected "foreach" keyword after "@" character It is due to the "Html" that I have inside my code. I understand the error but I do not know how to get around it. I want to avoid displaying the div that wraps the ValidationSummary unless there are actually errors to display otherwise the message about correcting your error shows up and displaces my form.
How do I hide this if ValidationSummary has no messages to display?