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?

0


source to share


2 answers


It turns out this is the behavior if you include the ClientValidationEnabled and the UnobtrusiveJavaScriptEnabled.

So setting them to false fixed my problem:



<add key="ClientValidationEnabled" value="false" />
<add key="UnobtrusiveJavaScriptEnabled" value="false" />

      

0


source


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; }

      

+1


source







All Articles