我试图让使用ASP.Net MVC 2.0 Beta版的DataAnnotations验证设置,但有以下型号:Asp.net MVC 2.0 DataAnnotations验证不正确发出JSON
public class Foo {
[Required] public string Bar {get;set;}
}
而以下代码在我看来:
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<Foo>" %>
<!-- later on -->
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Edit","Foo")) { %>
一切都几乎逐字形式的例子。发出的是:
<script type="text/javascript">
//<![CDATA[
EnableClientValidation({"Fields":[],"FormId":"form0"}, null);
//]]>
</script>
什么都不会发出来告诉任何JavaScript验证库(jQuery或MS Ajax,无所谓)来验证字段。验证确实发生在服务器端,但从不在客户端上,原因很明显。
注:我试图使用jQuery验证适配器。使用MS Ajax仍然会产生 Sys.Mvc.FormValidation.enableClientValidation({“Fields”:[],“FormId”:“form0”},null); 没有关于所需的属性。 – Mark 2009-12-15 20:43:27