【问题标题】:Bug? Client-side validation in ASP.NET MVC 2 causes ValidationSummary message to show even if there is no error漏洞? ASP.NET MVC 2 中的客户端验证会导致显示 ValidationSummary 消息,即使没有错误也是如此
【发布时间】:2010-02-17 21:55:28
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 更具体地说,可能缺少以下条目:.validation-summary-valid { display: none; }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多