mateuscb
mateuscb

Reputation: 10730

Recommended type to use in Metadata when Validating Model Data

This is a minor question, more of a curiosity. When creating MetaData class for Model Validation, what is the recommended variable type to use for each property.

In the MSDN example, they use Object for all properties

[MetadataType(typeof(ProductMD))]
public partial class Product {
    public class ProductMD {
        [StringLength(50),Required]
        public object Name { get; set; }
    }
}

Other examples online use the same type as the model:

[MetadataType(typeof(ProductMD))]
public partial class Product {
    public class ProductMD {
        [StringLength(50),Required]
        public String Name { get; set; }
        [Required]
        [DataType(DataType.Date)]
        public DateTime ArrivalDate { get; set; }
    }
}

Does the property type matter?

Upvotes: 0

Views: 263

Answers (1)

Max Toro
Max Toro

Reputation: 28618

The type does not matter, that's why you can just use Object. Properties must match by name.

Upvotes: 1

Related Questions