开发者

Bug? Client-side validation in ASP.NET MVC 2 causes ValidationSummary message to show even if there is no error

With client-side validation turned on in ASP.NET MVC 2 RC2, the validation summary message is visible even when I first load my Edit.aspx page. It does not show in bold red, however, just plain text. If I submit the form with an error, then the validation summary message turns bold red, and a list of errors appears below.

Here is the code that contains the validation summary:

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

Is this a bug or am I doing something wrong? If it is a bug, is there a workaround?

Note: If I turn off client validation, everything works properly.


Your site's CSS file is probably missing the entries necessary for ValidationSummary() to appear correctly. To fix this:

  1. Create a new MVC 2 RC 2 Empty WAP.
  2. Open its Content/Site.css in VS.
  3. Merge these entries into your original site's CSS file.

The empty WAP's Site.css contains the necessary classes, so this should solve your issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜