1

I'm sorry if the title is not representative enough.

So in my case, I want to build a more dynamic search form. Previously my search form only support equal operator. Now I want it to support another operators (contains, greater than etc).

This is what my previous search form model looks like:

public class PersonQuery
{
  [StringLength(100)]
  public string FirstName { get; set; }
  // the rest of the properties
}

And now the new query model is look like this:

public class AdvPersonQuery
{
  [StringLength(100)]
  public FilterField<string> FirstName { get; set; }
}

where 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; }
}

In this case I want the Value property data annotations refer to data annotations of property that use this class in the example above is FirstName property. So that when I put Value property of FirstName in View, the field will be validated based on the validation attribute defined on the FirstName property.

Moch Yusup
  • 1,266
  • 14
  • 14
  • This doesn't match the usual model of attributes very well, so a solution to this is likely to be extremely clever. Which is not necessarily a good thing. Instead, you may want to reconsider the use of this generic class. +1 in case there's a way to get it to work though. – Nathan Tuggy Jan 14 '15 at 03:46

0 Answers0