[英]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 below这
School
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.