Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you stop ValidationMessageFor displaying an error message on load?

I have added a validation message "CountryId custom error" to a view. Problem is it displays when I load the view initially as well as on POST.

<div class="editor-field">
@Html.DropDownList("CountryId", Model.GetCountries, "Please select", "0")
@Html.ValidationMessageFor(m => m.CountryId, "CountryId custom error")
</div>

How can I make it only display on the POST? If I omit the validation message the view behaves properly showing a default error on POST.

like image 995
Petras Avatar asked Feb 16 '26 23:02

Petras


1 Answers

This project was created as an empty MVC app and I deleted the site.css and started again. You can't do this if you want the validation to work as there is vital css in main.css that hides the messages!

Doh!!

like image 61
Petras Avatar answered Feb 18 '26 11:02

Petras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!