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>
what can a problem that data annotation attributes are not rendered?
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证的问题是 MVC 2 不渲染数据注释属性!
相反,MVC 2 创建定义所有验证规则的 JS 对象,然后 MicrosoftMvcValidation.js 使用它。
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.