[英]ASP.NET MVC 2 & xVal: Does Html.TextboxFor have a built-in ValidationMessage?
I'm using xVal for client-side validation, I have the following code: 我正在使用xVal进行客户端验证,我有以下代码:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.FiltersModel>" %>
<%@ Import Namespace="xVal.Rules" %>
<%@ Import Namespace="xVal.Html" %>
<% using( Html.BeginForm() ) { %>
<div id="filter-name-area">
<%: Html.LabelFor( x => x.Name )%>
<%: Html.TextBoxFor( x => x.Name, new { @class = "text" } )%>
<%-- <%: Html.ValidationMessageFor(x => x.Name) %> --%>
<button id="filters-add-row" style="float: right"></button>
</div>
<%} %>
<%= Html.ClientSideValidation<Models.FiltersModel>()%>
And this is my view model: 这是我的视图模型:
public class FiltersModel {
[Required]
[DisplayName( "Name:" )]
public string Name { get; set; }
}
Whether I comment <%: Html.ValidationMessageFor(x => x.Name) %>
or not, I still get the validation message. 无论我是否评论
<%: Html.ValidationMessageFor(x => x.Name) %>
,我仍然会收到验证消息。
How come? 怎么会?
Thanks for your help. 谢谢你的帮助。
Because xVal generates validation messages based on model metadata automatically. 因为xVal基于模型元数据自动生成验证消息。
The Html.ValidationMessage()
and Html.ValidationMessageFor()
are there for the built-in MVC validation (so you don't use them with xVal). Html.ValidationMessage()
和Html.ValidationMessageFor()
用于内置MVC验证(因此,不要将它们与xVal一起使用)。
Edit: This is true for client side validation. 编辑:这对于客户端验证是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.