Hi Atanas,
Much appreciated.
Actually I have already done something similar, but in a more generic way by using Attributes:
public static void ConvertFilterToMatchDestination<
T
>(this FilterDescriptor _this)
{
PropertyInfo prop = typeof(T).GetProperty(_this.Member);
if (prop == null)
return;
Attribute att = prop.GetCustomAttribute(typeof(KendoFilterAttribute));
if (att != null && att is KendoFilterAttribute)
{
KendoFilterAttribute attribute = att as KendoFilterAttribute;
if (!string.IsNullOrEmpty(attribute.BaseFieldName))
_this.Member = attribute.BaseFieldName;
if (attribute.ConvertDecimalToInt)
{
decimal d = 0;
if (decimal.TryParse(_this.Value.ToString(), out d))
_this.Value = decimal.ToInt32(d);
}
}
}
There are two problems when dealing with filtering in MVC: 1 The domain model and the view model doesn't necessary share property names (the reason for this question), 2 there is no such things as an int filter in Kendo.Grid, only a decimal filter.
The last thing cause problems when building dynamic expressions (.Net Expression) because int database fields is not comparable with decimals values.
Anyway, I will accept your comment as the answer, because the code does what I asked for :-)
Thanks.