views:

368

answers:

1

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.

+9  A: 

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.

Levi
You got it, Levi. Thanks.
DanM
More specifically, it's the following entry which is probably missing: `.validation-summary-valid { display: none; }`
Yann Trevin