We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

NullReferenceException with PerformWhereFilter

Hello Syncfusion Team,

Since I wanted to use DataManager and DataOperations object, after reading this thread, I tryed UrlAdaptor.
I'm able to display the grid, paging it, using select dropdown in edit, but the filter on the columns throws a NullReferenceException.

This is the start of stacktrace
System.NullReferenceException: Object reference not set to an instance of an object.
   in PromoProCore.Controllers.ElementiListeAnagraficheController.GetColumnType(IEnumerable dataSource, String filterString, Type type)
   in PromoProCore.Controllers.ElementiListeAnagraficheController.PerformWhereFilter(IEnumerable dataSource, List`1 whereFilter, String condition)
   in PromoProCore.Controllers.ElementiListeAnagraficheController.<ElementiListaJSON>d__4.MoveNext()

Syncfusion version is 15.3600.0.29

Based on my playing around with WebApiAdaptor (I made a custom orderby), I think the problem lies in the way ASP.NET pass property name to the view.
I had a similar error while calling
var propertyInfo = entityType.GetProperty(propertyName),
because the property name first letter was lower case (as opposed to the property name in the class)

Following, the json the view is passing to the controller:
{"requiresCounts":true,"where":[{"isComplex":false,"field":"codiceElemento","operator":"startswith","value":"56","ignoreCase":true}],"skip":0,"take":10}

The definition of object properties:
public class ElementoAnagraficaVM
{
        [Display(Name = "Codice elemento")]
        [MaxLength(50)]
        public string CodiceElemento { get; set; }
        [Display(Name = "Descrizione")]
        [MaxLength(100)]
        public string DescrizioneElemento { get; set; }
        [Display(Name = "Prezzo iniziale")]
        public decimal? PrezzoIniziale { get; set; }
        [Display(Name = "Sconto")]
        public decimal? Sconto { get; set; }
        [Display(Name = "Tipologia sconto")]
        [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
        public eTipoScontoDB TipoSconto { get; set; }
       
        public int Id { get; set; }
        public int IdLista { get; set; }
}


3 Replies

SA Saravanan Arunachalam Syncfusion Team September 12, 2017 06:18 AM UTC

Hi Chiara, 
Thanks for contacting Syncfusion’s support. 
We have analyzed your query and we have faced the exception thrown as “Object reference not set to an instance of an object” while performing filter operation which is due to camel case which returns the field name as “employeeID” while we filter the EmployeeID column.   
  
 In ASP.Net Core CamelCase property of JSONFormatter changes the case of the “Items” to “items” while returning the response from the server-end, so the reported issue occurs.    
To overcome from this we suggest you to follow the below code in the startup.cs project   
public void ConfigureServices(IServiceCollection services)  
        {  
            // Add framework services.  
            ...  
  
            services.AddMvc()  
            .AddJsonOptions(x =>  
            {  
                x.SerializerSettings.ContractResolver = null;  
            });  
                   ...  
        }  
 
 
 
Else refer to the following document to solve casing problem and also mention field values in camelcase.      
 
Note:  You can change the field as per the data returned value.  
  
Example: if you have EmployeeID field you can set as EmployeeID itself instead of employeeID when you performed the above solution. 
 
Refer the code example. 

<e-columns> 
            <e-column field="OrderID" header-text="Order ID" is-primary-key="true” text-align="Right" width="75"></e-column> 
                        <e-column field="EmployeeID" header-text="Employee ID" text-align="Right" width="75"></e-column>        //assign the field as it is like which returns from database 
</e-columns> 
 
Refer the screenshot below which show performing filtering operations. 
Figure 1: shows the filtered data with EmployeeID as 1 in server side  
 
  

Figure 2: shows the grid with Filtered data  
  
  
 
We have also prepared a sample and the same can be downloaded from the below link.  
Link: 
  
Regards, 
Saravanan A. 



CD Chiara De Acetis September 12, 2017 08:21 AM UTC

Thank you for your answer.

The solution is working fine, but breaks my angular code (I use it in different pages).

Since I cannot change it now, I implemented the following workaround:

if (dataManager.Where != null && dataManager.Where.Count > 0) //Filtering
{
                foreach(var where in dataManager.Where)
                {
                    where.Field = char.ToUpper(where.Field[0]) + where.Field.Substring(1);//make first letter uppercase
                }
                data = ops.PerformWhereFilter(data, dataManager.Where, dataManager.Where[0].Operator);
}


Thanks for the answer and the examples!

Regars,

Chiara



SA Saravanan Arunachalam Syncfusion Team September 13, 2017 05:10 AM UTC

Hi Chiara,  
Thanks for your update.            
We are happy that the provided information helped you. 
Regards, 
Saravanan A. 


Loader.
Live Chat Icon For mobile
Up arrow icon