2011-09-30 108 views
0

数据注释属性不会呈现的问题是什么?asp.net mvc 2项目不提供数据注释属性

的web.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> 
+1

不是mvc 3的“不显眼javascript”功能的一部分吗? –

+0

究竟是什么问题? – samack

+0

问题是,html 没有数据注释属性 – Cherven

回答

0

与验证的问题是MVC 2不呈现数据注解的属性!

而是MVC 2创建定义所有验证规则的JS对象,然后MicrosoftMvcValidation.js可以使用它。

+0

哪些指向我的评论...它们被渲染为mvc3的一部分,而不是mvc2。 –

+0

μBio是的,你问的是正确的问题,但我没有觉得它有用的一开始。 – Cherven

相关问题