Asp.net mvc 5 ASP.Net MVC:ValidationResult不接受int.tostring()作为成员名称

Asp.net mvc 5 ASP.Net MVC:ValidationResult不接受int.tostring()作为成员名称,asp.net-mvc-5,Asp.net Mvc 5,代码取自 如果我这样写的话 yield return new ValidationResult("Income cannot be negative", Income.ToString()); 然后得到错误,但当我们传递一个字符串变量时,就没有问题了。所以,如果我需要验证许多int类型属性,那么我是否需要将这些属性名称放入 string array like var pIncome = new[] { "Income" }; ? 如果数组中有一些多元素名称,那么如何将其引用为Validat

代码取自

如果我这样写的话

yield return new ValidationResult("Income cannot be negative", Income.ToString());
然后得到错误,但当我们传递一个字符串变量时,就没有问题了。所以,如果我需要验证许多int类型属性,那么我是否需要将这些属性名称放入

string array like  var pIncome = new[] { "Income" }; ?
如果数组中有一些多元素名称,那么如何将其引用为
ValidationResult-ctor
的第二个参数


请帮忙。谢谢

如果我没记错的话,它应该是collection(IEnumerable),所以它必须是[]类型。更改为.tostring()将不会生成数组

public ValidationResult(string errorMessage, IEnumerable<string> memberNames); 
公共验证结果(字符串errorMessage,IEnumerable MemberName); 此外,重载的ctor为模型中的一个或多个字段分配了验证错误,如果您想省略传递的成员名称,我猜该错误不会与任何字段关联,而是与表单关联。请参考这里的另一个好答案

string array like  var pIncome = new[] { "Income" }; ?
public ValidationResult(string errorMessage, IEnumerable<string> memberNames);