开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜