I am working on an MVC 4 project that is constantly showing the ValidationMessage even on a simple GET method that does no validation or model binding of complex types:
//location/{locationId}/announcement
[HttpGet]
public ActionResult LocationMakeAnnouncement(int locationId)
{
var pageViewModel = this.BuildLocationMakeAnnouncementViewModel(locationId);
return View(pageViewModel);
}
The BuildLocationMakeAnnouncementViewModel
only builds up the ViewModel and doesn't 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>
Outputting the ModelState shows that it does not have any errors
@ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1)
Why would ValidatioMessage output the when there are no errors?
ANY suggestions?
Turns out this is the behavior if you enable ClientValidationEnabled and UnobtrusiveJavaScriptEnabled.
So setting them to false fixed my problem:
<add key="ClientValidationEnabled" value="false" />
<add key="UnobtrusiveJavaScriptEnabled" value="false" />