Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 551
devuxer Avatar asked Feb 17 '10 21:02

devuxer


1 Answers

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.

like image 108
Levi Avatar answered Sep 28 '22 00:09

Levi