ivalidatableobject

ValidationResult Returned From IValidatableObject.Validate Is Not Localized

眉间皱痕 提交于 2020-01-04 06:12:00
问题 In my ASP.NET MVC3 site, I am using the following as a View Model: using DataResources = Namespace.For.The.Localization.Resources.IndexViewModel; public class IndexViewModel, IValidatableObject { private string _field1_check_value = "foo"; private string _field2_check_value = "bar"; [Required(ErrorMessageResourceName="Validation_Field1_Required", ErrorMessageResourceType=typeof(DataResources))] [DataType(DataType.Text)] public string Field1 { get; set; } [Required(ErrorMessageResourceName=

IDataErrorInfo vs IValidatableObject?

寵の児 提交于 2019-12-04 02:59:45
问题 Currently my business objects implement IDataErrorInfo . Since I intend to use these libraries in ASP.NET MVC 3, I figure I should implement IValidatableObject as well or maybe instead of. Does WPF work with IValidatableObject ? How do DataAnnotations fit into the picture? 回答1: IValidatableObject is an interface for verifying whole object level errors. It is your responsibility to implemts it by verifying data annotations or other techniques. MVC has native support for data annotations so you

IValidatableObject Validate method firing when DataAnnotations fails

↘锁芯ラ 提交于 2019-11-27 13:21:56
I've a ViewModel which has some DataAnnotations validations and then for more complex validations implements IValidatableObject and uses Validate method. The behavior I was expecting was this one : first all the DataAnnotations and then, only if there were no errors, the Validate method. How ever I find out that this isn't always true. My ViewModel (a demo one) has three fileds one string , one decimal and one decimal? . All the three properties have only Required attribute. For the string and the decimal? the behavior is the expected one, but for the decimal , when empty, Required validation

IValidatableObject Validate method firing when DataAnnotations fails

為{幸葍}努か 提交于 2019-11-26 22:23:03
问题 I've a ViewModel which has some DataAnnotations validations and then for more complex validations implements IValidatableObject and uses Validate method. The behavior I was expecting was this one: first all the DataAnnotations and then, only if there were no errors, the Validate method. How ever I find out that this isn't always true. My ViewModel (a demo one) has three fileds one string , one decimal and one decimal? . All the three properties have only Required attribute. For the string and

How do I use IValidatableObject?

不羁的心 提交于 2019-11-25 22:59:52
问题 I understand that IValidatableObject is used to validate an object in a way that let\'s one compare properties against each other. I\'d still like to have attributes to validate individual properties, but I want to ignore failures on some properties in certain cases. Am I trying to use it incorrectly in the case below? If not how do I implement this? public class ValidateMe : IValidatableObject { [Required] public bool Enable { get; set; } [Range(1, 5)] public int Prop1 { get; set; } [Range(1