如果标题不够具有代表性,我很抱歉。
所以在我的情况下,我想构建一个更动态的搜索表单。以前我的搜索表单只支持相等运算符。现在我希望它支持另一个运算符(包含,大于等)。
这是我以前的搜索表单模型:
public class PersonQuery
{
[StringLength(100)]
public string FirstName { get; set; }
// the rest of the properties
}
现在新的查询模型如下所示:
public class AdvPersonQuery
{
[StringLength(100)]
public FilterField<string> FirstName { get; set; }
}
其中FilterField:
public class FilterField<T>
{
// in this case I want the [StringLength(100)] attribute
// or any other data annotation that is put on property that use this class to be used here
public T Value { get; set; }
public OperatorTypes Operator { get; set; }
}
在这种情况下,我希望 Value 属性数据注释引用上面示例中使用此类的属性的数据注释是 FirstName 属性。因此,当我在View中放置FirstName的 Value 属性时,将根据FirstName属性上定义的验证属性验证该字段。