简体   繁体   English

嵌套的 class 属性过滤器不起作用 MVC5 NonFactor Grid

[英]Nested class property filter not working MVC5 NonFactor Grid

I have integrated NonFactors Grid in my Mvc5 application.我在我的 Mvc5 应用程序中集成了 NonFactors Grid。 Its filtering not working on inner class propery name however it works fine on its own properties.它的过滤不适用于内部 class 属性名称,但它在其自身的属性上工作正常。 I have one class which is User and this contains School object onto it.我有一个 class 是User ,其中包含School object 。 This School class a property as Name and I bind it to model as belowSchool class 一个property作为Name ,我将它绑定到 model 如下

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 .当我在User Name上应用过滤器时,它工作得很好,但同样不适用于School Name Its giving error in _Grid.cshtml saying Object reference not set to an instance of an object.它在_Grid.cshtml中给出错误说Object reference not set to an instance of an object. ' Please refer below. '请参阅下文。

在此处输入图像描述

Can you please guide how to fix it?你能指导如何解决它吗? Thank You!谢谢你!

Adding null check on column value solved the problem.添加 null 检查列值解决了问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM