I'm using Kendo UI for aspnet core MVC. And whenever I use the search with a numeric value I get an exception:
Provided expression should have string type (Parameter 'stringExpression')
It works however great with strings. So for example: "test" works but 5 throws an exception.
My search in my grid is configured like this
.Search(s => {
s.Field(c => c.IncidentEvent, "contains");
s.Field(c => c.CourseNumber, "contains");
s.Field(c => c.CourseCode, "contains");
s.Field(c => c.ActivityType, "contains");
s.Field(c => c.SeverityType, "contains");
All my fields are of string type. However I expect kendo grid to be able to parse integers as well when doing a search.
Is there a way around this? How can I get my search to work with numbers as well?
I tried something based on this answer:
https://www.telerik.com/forums/grid-filter-on-guid-provided-expression-should-have-string-type
When I use this function to set the membertype it works:
private void ModifyFilters(IList<IFilterDescriptor> filters) { if (filters.Any()) { foreach (var filter in filters) { var descriptor = filter as Kendo.Mvc.FilterDescriptor; if (descriptor != null) { descriptor.Value = descriptor.Value.ToString(); descriptor.MemberType = typeof(string); } else if (filter is CompositeFilterDescriptor) { ModifyFilters(((CompositeFilterDescriptor)filter).FilterDescriptors); } } } }