我安装了斯科特的柯克兰DataAnnotationsExtensions。
在我的模型里:
[Numeric]
public double expectedcost { get; set; }在我看来:
@Html.EditorFor(model => model.expectedcost)现在,当页面试图呈现时,我得到以下错误:
非突出客户端验证规则中的
验证类型名称必须是唯一的。多次看到下列验证类型: number
知道我为什么会犯错吗?
发布于 2011-03-24 11:03:44
快速的答案是简单地删除属性
[Numeric]更长的解释是,通过设计,验证已经添加了一个数据-val-数字,因为它的类型为double。通过添加一个数字,您就是在重复验证。
这样做是可行的:
[Numeric]
public string expectedcost { get; set; }因为变量是string类型的,所以您要添加Numeric属性。
希望这能有所帮助
发布于 2015-10-06 19:21:33
我基本上也遇到了同样的问题,我设法用下面的代码来解决这个问题:(如这里所回答的:ASP.NET MVC - "Validation type names must be unique.")
使用系统;使用System.Web.Mvc;以及ValidationRule:
公共类RequiredIfValidationRule : ModelClientValidationRule {私有Chars = "abcdefghijklmnopqrstuvwxyz";
public RequiredIfValidationRule(string errorMessage, string reqVal,
string otherProperties, string otherValues, int count)
{
var c = "";
if (count > 0)
{
var p = 0;
while (count / Math.Pow(Chars.Length, p) > Chars.Length)
p++;
while (p > 0)
{
var i = (int)(count / Math.Pow(Chars.Length, p));
c += Chars[Math.Max(i, 1) - 1];
count = count - (int)(i * Math.Pow(Chars.Length, p));
p--;
}
var ip = Math.Max(Math.Min((count) % Chars.Length, Chars.Length - 1), 0);
c += Chars[ip];
}
ErrorMessage = errorMessage;
// The following line is where i used the unique part of the name
// that was generated above.
ValidationType = "requiredif"+c;
ValidationParameters.Add("reqval", reqVal);
ValidationParameters.Add("others", otherProperties);
ValidationParameters.Add("values", otherValues);
}}
我希望这能帮到你。
https://stackoverflow.com/questions/5416509
复制相似问题