我有以下解决方案结构:
(项目)AppNameSpace.Model
内部ModelValidation.cs
我有
[MetadataType(typeof(CMPlan.MetaData))]
public partial class CMPlan
{
internal class MetaData
{
[Range(100.0, double.MaxValue, ErrorMessage = "Invalid number of people.")]
public double peopleCount { get; set; }
}
}
我试图保存peopleCount
小于100,但它通过了。问题是如何指导它进行验证?
修改
以下语法也无济于事:
[MetadataType(typeof(CMPlanMetaData))]
public partial class CMPlan
{
public int newProperty {get;set;} // This, however, shows up like expected
}
public class CMPlanMetaData
{
[Range(100.0, double.MaxValue, ErrorMessage = "Invalid number of people.")]
public double peopleCount { get; set; }
}