开发者

asp.net mvc 2 project does not render data annotation attributes

开发者 https://www.devze.com 2023-04-09 11:07 出处:网络
what can a problem that data annotation attributes are not rendered? w开发者_JAVA技巧eb.config <appSettings>

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

精彩评论

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

关注公众号