错误?ASP.NET MVC 2中的客户端验证导致ValidationSummary消息显示即使没有错误

dev*_*xer 6 validation asp.net-mvc html-helper client-side asp.net-mvc-2

在ASP.NET MVC 2 RC2中打开客户端验证后,即使我第一次加载Edit.aspx页面,验证摘要消息也是可见的.它没有用粗体红色显示,只是纯文本.如果我提交带有错误的表单,则验证摘要消息将变为粗体红色,并在下面显示错误列表.

以下是包含验证摘要的代码:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.ViewModels.PersonEditorViewModel>" %>

<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>

<%  Html.EnableClientValidation(); %>

<%  using (Html.BeginForm())
    {
%>
        <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>
        <%= Html.EditorForModel() %>
        <p>
            <input type="submit" value="Save" />
        </p>
<%
    }
%>
Run Code Online (Sandbox Code Playgroud)

这是一个错误还是我做错了什么?如果它是一个bug,是否有解决方法?

注意:如果我关闭客户端验证,一切正常.

Lev*_*evi 11

您的网站的CSS文件可能缺少ValidationSummary()正确显示所需的条目.解决这个问题:

  1. 创建一个新的MVC 2 RC 2空WAP.
  2. 在VS中打开其Content/Site.css.
  3. 将这些条目合并到原始站点的CSS文件中.

空WAP的Site.css包含必要的类,因此这应该可以解决您的问题.