asp.net mvc 2 project does not render data annotation attributes
what can a problem that data annotation attributes are not rendered?
w开发者_JAVA技巧eb.config
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
C#
public class SearchCriteria
{
[Required]
public string ControlNo { get; set; }
[Required]
public string Insured { get; set; }
[Required]
public string PolicyNumber { get; set; }
}
ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Core.SearchCriteria>" %>
<%@ Import Namespace="Core" %>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.ControlNo) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.ControlNo) %>
<%= Html.ValidationMessageFor(model => model.ControlNo) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Insured) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Insured) %>
<%= Html.ValidationMessageFor(model => model.Insured) %>
</div>
the problem with validation was that MVC 2 does not render data annotation attributes !!!
instead MVC 2 creates JS object that defines all validation rules and then MicrosoftMvcValidation.js works with it.
精彩评论