strange data annotations issue in MVC 2

Posted by femi on Stack Overflow See other posts from Stack Overflow or by femi
Published on 2010-06-07T15:24:32Z Indexed on 2010/06/07 15:32 UTC
Read the original article Hit count: 771

Filed under:
|
|
|
|

Hello,

I came across something strange when creating an edit form with MVC 2. i realised that my error messages come up on form sumission even when i have filled ut valid data! i am using a buddy class which i have configured correctly ( i know that cos i can see my custom errors).

Here is the code from the viewmodel that generates this;

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TG_Careers.Models.Applicant>" %>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
        <%= Html.ValidationSummary() %>
        <% Html.EnableClientValidation(); %>
        <% using (Html.BeginForm()) {%>
         <div class="confirm-module">
  <table cellpadding="4" cellspacing="2">
 <tr>
  <td><%= Html.LabelFor(model => model.FirstName) %>
</td>
  <td><%= Html.EditorFor(model => model.FirstName) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.FirstName) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.MiddleName) %></td>
  <td><%= Html.EditorFor(model => model.MiddleName) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.MiddleName) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.LastName) %></td>
  <td><%= Html.EditorFor(model => model.LastName) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.LastName) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.Gender) %></td>
  <td><%= Html.EditorFor(model => model.Gender) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.Gender) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.MaritalStatus) %></td>
  <td> <%= Html.EditorFor(model => model.MaritalStatus) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.MaritalStatus) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.DateOfBirth) %></td>
  <td><%= Html.EditorFor(model => model.DateOfBirth) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.DateOfBirth) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.Address) %></td>
  <td><%= Html.EditorFor(model => model.Address) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.Address) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.City) %></td>
  <td><%= Html.EditorFor(model => model.City) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.City) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.State) %></td>
  <td><%= Html.EditorFor(model => model.State) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.State) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.StateOfOriginID) %></td>
  <td><%= Html.DropDownList("StateOfOriginID", new SelectList(ViewData["States"] as IEnumerable, "StateID", "Name", Model.StateOfOriginID))%></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.StateOfOriginID) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.CompletedNYSC) %></td>
  <td><%= Html.EditorFor(model => model.CompletedNYSC) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.CompletedNYSC) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.YearsOfExperience) %></td>
  <td><%= Html.EditorFor(model => model.YearsOfExperience) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.YearsOfExperience) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.MobilePhone) %></td>
  <td><%= Html.EditorFor(model => model.MobilePhone) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.MobilePhone) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.DayPhone) %></td>
  <td> <%= Html.EditorFor(model => model.DayPhone) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.DayPhone) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.CVFileName) %></td>
  <td><%= Html.EditorFor(model => model.CVFileName) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.CVFileName) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.CurrentPosition) %></td>
  <td><%= Html.EditorFor(model => model.CurrentPosition) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.CurrentPosition) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.EmploymentCommenced) %></td>
  <td><%= Html.EditorFor(model => model.EmploymentCommenced) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.EmploymentCommenced) %></td>
 </tr>
 <tr>
  <td><%= Html.LabelFor(model => model.DateofTakingupCurrentPosition) %></td>
  <td><%= Html.EditorFor(model => model.DateofTakingupCurrentPosition) %></td>
 </tr>
 <tr>
  <td colspan="2"><%= Html.ValidationMessageFor(model => model.DateofTakingupCurrentPosition) %></td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
</table>
<p>
 <input type="submit" value="Save Profile Details" />

</p>
</div>


    <% } %>

Any ideas on this one please? Thanks

© Stack Overflow or respective owner

Related posts about mvc

Related posts about validation