Oxygen
Oxygen

Reputation: 871

Nested class property filter not working MVC5 NonFactor Grid

I have integrated NonFactors Grid in my Mvc5 application. Its filtering not working on inner class propery name however it works fine on its own properties. I have one class which is User and this contains School object onto it. This School class a property as Name and I bind it to model as below

columns.Add(model => model.School.Name).Titled("School Name");
columns.Add(model => model.UserName).Titled("User Name");

When I apply a filter on User Name it works perfectly fine but same is not working on School Name. Its giving error in _Grid.cshtml saying Object reference not set to an instance of an object.' Please refer below.

enter image description here

Can you please guide how to fix it? Thank You!

Upvotes: 0

Views: 920

Answers (1)

Oxygen
Oxygen

Reputation: 871

Adding null check on column value solved the problem.

columns.Add(model => model.School == null ? null : model.School.Name).Titled("School Name").Filterable(true); 

Upvotes: 0

Related Questions