以下是我流利的验证器
[Validator(typeof(testvalidator))]
public class test
{
.....
}
public class testvalidator: AbstractValidator<test>
{
public testvalidator()
{
Custom(testvalidationmethod);
}
public ValidationFailure testvalidationmethod(test t)
{
return ValidationFailure("","error occurred in test validation method ");
}
}
使用方法
testvalidator tv = new testvalidator();
var result =tv.(test);
我可以看到
result.Errors
中的错误信息。但是我想在视图中显示错误信息。我尝试使用Html.ValidationSummary()
并设置为true
和false
,但是没有起作用。需要做什么才能在视图中显示呢?我正在阅读教程。但它展示了如何在console
上显示,这在实际应用中几乎不需要。我该怎么使它工作?