Kendo MVC包装纸网格。如何指定嵌套模型字段的数据类型?

发布于 2025-02-13 06:53:19 字数 554 浏览 0 评论 0原文

我有数百个网格的项目工作。特别是在一个网格上,原始设计师创建了一个视图,并将其添加为驱动器模型中的嵌套模型。这是一个问题,因为Kendo似乎无法检测以这种方式嵌套的字段类型。当它不能时,它假设字段是字符串。

在我的特殊情况下,我有两个字段,其中包含我们要过滤的日期,但是由于此,日期过滤被打破了。

我能够找到许多在数据源中指定它的示例,但仅用于jQuery网格(一个示例: https://docs.telerik.com/kendo-ui/knowledge-base/use-nested-model-properties )。我无法将其转换为MVC,因为这些方法没有排队。

关于如何在MVC中执行此操作的任何想法?注意:我还尝试将过滤器上的UI更改为迄今为止,但这也不起作用。我有一个堆栈跟踪声称需要的日期是字符串。

I have a project work work with hundreds of grids. On one grid in particular, the original designer created a view and added it as a nested model inside our driver model. This is a problem because Kendo seems to not be able to detect the field type of a field nested this way. When it can't, it assumes the field is a string.

In my particular case, I have two fields that contain dates that we want to filter on, but the date filtering is broken because of this.

I was able to find numerous examples of specifying it in the data source, but only for jquery grids (one example: https://docs.telerik.com/kendo-ui/knowledge-base/use-nested-model-properties ). I can't convert this to mvc because the methods aren't lining up.

Any idea on how to do this in mvc? Note: I also tried just changing the UI on the filter to date and that didn't work either. I got a stack trace claiming date needed to be a string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两仪 2025-02-20 06:53:20

据我了解,传递给网格字段的模型是这样的:

public class OrderViewModel
{
    public int OrderID
    {
        get;
        set;
    }

    public CityModel ShipCity
    {
        get;
        set;
    }
}

public class CityModel
{
    public int CityID 
    { 
         get; 
         set;
    };

    public string CityName 
    { 
         get;
         set;
    };

}

然后您可以使用 clientTemplate配置要获取CityName填充列:

columns.Bound(p => p.ShipCity).ClientTemplate("#=ShipCity.CityName#");

有关更多信息,请参阅 Kendo UI模板文章
或者
此论坛答案显示网格的数据源模型配置中的嵌套字段

As far as I understand the model passed to the Grid's field is structured like this:

public class OrderViewModel
{
    public int OrderID
    {
        get;
        set;
    }

    public CityModel ShipCity
    {
        get;
        set;
    }
}

public class CityModel
{
    public int CityID 
    { 
         get; 
         set;
    };

    public string CityName 
    { 
         get;
         set;
    };

}

Then you can utilize the ClientTemplate configuration to get the CityName to populate the column:

columns.Bound(p => p.ShipCity).ClientTemplate("#=ShipCity.CityName#");

For more information refer to the Kendo UI Templates article
or
this forum answer that shows how to set a default to a nested field in a Grid's DataSource Model configuration.

む无字情书 2025-02-20 06:53:20

不幸的是,根据Telerik的说法,事实是您根本无法做我想做的事情。解决方案是将模型弄平。我将可疑的字段拉到了主模型中的未映射字段中。
他们回应的相关部分:

在MVC中,嵌套属性是另一个模型的属性。由于Telerik UI网格需要数据的平坦结构,因此可以借助客户端网板显示嵌套属性,但始终将键入字符串。
为了实现所需的行为,我建议制作尖头的日期字段 - 主要模型的一部分,并将其用作固定数据。

链接: https://www.telerik.com/forums/kendo-mvc-wrapper-grid-how-do-i-pecify-the-the-data-type-the-data-type of-a-a-nested-model-field

这里的警告是,您不能将linq-for for linq-for for linq-for cerquies dataSource过滤到一个未映射的字段,因为它不存在,但就我而言,.tolist()并未导致任何性能问题,因为数据集很小,只有几百个记录。
但是,您可以编辑传入的dataSourcerequest对象,以修改过滤器并在控制器读取后指向子模型。

Unfortunately, according to Telerik , the fact is that you simply can't do what I was trying to do. The solution is to flatten the model. I pulled the questionable fields into notmapped fields in the master model.
The relevant part of their response:

In MVC the nested properties are properties to another Model. As the Telerik UI Grid needs a flat structure of data, the nested properties could be shown with the help of a ClientTemplate, but they will always be string typed.
In order to achieve the desired behavior, I would recommend making the pointed Date fields - part of the Main Model and using them as flat data out of the box.

Link: https://www.telerik.com/forums/kendo-mvc-wrapper-grid-how-do-i-specify-the-data-type-of-a-nested-model-field

The caveat here is you can't filter a linq-for-queries datasource to a notmapped field because it doesn't exist in it but in my case, a .toList() didn't cause any performance problems because the dataset was small, with only a few hundred records.
However, you can edit the incoming DatasourceRequest object to modify the filters and sorts to point at the sub model, after your controller read is hit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文