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

时间:2010-02-17 21:55:29

标签: asp.net-mvc validation asp.net-mvc-2 client-side html-helper

在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>
<%
    }
%>

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

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

1 个答案:

答案 0 :(得分:11)

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

  1. 创建一个新的MVC 2 RC 2空WAP。
  2. 在VS。中打开其Content / Site.css。
  3. 将这些条目合并到原始网站的CSS文件中。
  4. 空WAP的Site.css包含必要的类,因此这可以解决您的问题。