我正在开发一个 MVC 4 项目,该项目即使在一个简单的 GET 方法上也不断显示 ValidationMessage,该方法不进行复杂类型的验证或模型绑定:
//location/{locationId}/announcement
[HttpGet]
public ActionResult LocationMakeAnnouncement(int locationId)
{
var pageViewModel = this.BuildLocationMakeAnnouncementViewModel(locationId);
return View(pageViewModel);
}
唯一构建 ViewModel并且BuildLocationMakeAnnouncementViewModel
不触及 ModelState。
然后在视图上我有:
<span class="errorArea">@Html.ValidationMessage("ProductText", " ", new { @class = "inputErrorIcon" })</span>
发出:
<span class="errorArea"><span class="field-validation-valid inputErrorIcon" data-valmsg-for="ProductText" data-valmsg-replace="false"> </span></span>
输出 ModelState 表明它没有任何错误
@ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1)
没有错误时,为什么 ValidatioMessage 会输出?
有什么建议么?