MVC3 DataAnnotationsExtensions错误使用数字属性 [英] MVC3 DataAnnotationsExtensions error using numeric attribute

查看:136
本文介绍了MVC3 DataAnnotationsExtensions错误使用数字属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了斯科特的柯克兰DataAnnotationsExtensions。

I've installed Scott's Kirkland DataAnnotationsExtensions.

在我的模型我有:

[Numeric]
public double expectedcost { get; set; }

在我看来:

@Html.EditorFor(model => model.expectedcost)

现在,当页面试图使我得到以下错误:

Now, when the page tries to render I get the following error:

验证类型名称
  客户端验证规则必须
  独特。下面的验证类型
  被视为不止一次:数

Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: number

任何想法,为什么我得到这个错误吗?

Any ideas why I'm getting the error ?

推荐答案

简单的回答仅仅是删除属性。

The quick answer is simply remove the attribute

[Numeric]

较长的解释是,通过设计,验证已经增加了的数据-VAL-号的,因为它是类型的的。通过添加的数字的要复制的验证。

The longer explanation is that by design, validation already adds a data-val-number because it's of type double. By adding a Numeric you are duplicating the validation.

这个作品:

[Numeric]
public string expectedcost { get; set; }

由于变量类型的字符串的和你所添加的的数字的属性。

because the variable is of type string and you are adding the Numeric attribute.

希望这有助于

这篇关于MVC3 DataAnnotationsExtensions错误使用数字属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆