ValidationMessage shows on initial GET method
I'm working on an MVC 4 project that consistently shows ValidationMessage even in a simple GET method that doesn't perform complex type model validation or binding:
//location/{locationId}/announcement
[HttpGet]
public ActionResult LocationMakeAnnouncement(int locationId)
{
var pageViewModel = this.BuildLocationMakeAnnouncementViewModel(locationId);
return View(pageViewModel);
}
BuildLocationMakeAnnouncementViewModel
only creates the ViewModel and does not touch the ModelState.
Then on the view I have:
<span class="errorArea">@Html.ValidationMessage("ProductText", " ", new { @class = "inputErrorIcon" })</span>
Which emits:
<span class="errorArea"><span class="field-validation-valid inputErrorIcon" data-valmsg-for="ProductText" data-valmsg-replace="false"> </span></span>
ModelState output shows it has no errors
@ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1)
Why does ValidatioMessage output when there are no errors?
Any suggestions?
source to share
If you want client validation to be activated I had a similar problem with ValidationSummary
but I just believe these things are rendered. All you have to do is style the "valid" material in display: none
. In your case, it looks like this:
.field-validation-valid { display: none; }