kendo网格将DateTime显示为/ Date(*************)/

时间:2018-10-10 15:33:42

标签: c# datetime kendo-ui grid kendo-grid

我的DateTime列在Kendo网格中显示为“ / Date(1520608915000)/”。您能否建议应如何解决?我尝试添加几个模板,但是日期的前端格式每次都保持数字。这是我的代码:

Column0 = Convert.ToDateTime("3/9/2018 4:21:55 PM"),

@(Html.Kendo().Grid<Project.Mvc.Models.GridViewModel>()
            .Name("GName")
            .Columns(columns =>
            {
                columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).Encoded(false).ClientTemplate(null);
                columns.Bound(c => c.Column1).Title("Name").Width(100).Visible(true).Encoded(false).ClientTemplate(null);
            })
            .AutoBind(false)
            .HtmlAttributes(new { style = "height:" + gridHeight + "px;width:" + gridWidth + "px;" })
            .Scrollable()
            .Selectable()
            .Sortable()         
            .ColumnMenu()
            .Resizable(resize => resize.Columns(false))
            .Pageable(pageable => pageable
                .Enabled(pageableEnabled)
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(7)
            )
            .Filterable(filterable => filterable
                .Extra(false)
                .Operators(operators => operators
                    .ForString(str => str.Clear()
                        .StartsWith(@Project.Mvc.Resources.StartsWith)
                        .Contains(@Project.Mvc.Resources.Contains)
                    ))
                )
                .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action(readAction, controller).Data(datasourceParameterAction))
                .Model(model => model.Id(c => c.Column0))
                )
                .Events(events => events
                .Change("GNameChange")
                .DataBound("GNameBound")
                )

     )

下面是我尝试过的事情(没有成功):

columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).Format("{0: M/d/yyyy h:mm:ss tt}").Encoded(false).ClientTemplate(PopupColumnTemplates[0]);

columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).Format("{0: M/d/yyyy h:mm:ss tt}").Encoded(false);

columns.Bound(c => c.Column0).Title("Date and Time").Width(150).Visible(true).Format("{0: M/d/yyyy h:mm:ss tt}");

columns.Bound(c => c.Column0).Title("Date and Time").Width(150).Visible(true).Format("{0: yyyy}");

columns.Bound(c => c.Column0).Title("Date and Time").Width(150).Visible(true).Format("{0: yyyy}").ClientTemplate("#= kendo.toString(Column0, \"yyyy\") #");

2 个答案:

答案 0 :(得分:0)

我找到了解决该问题的有效方法:

columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).ClientTemplate("#= kendo.toString(kendo.parseDate(Column0, 'M/d/yyyy h:mm:ss tt'), 'M/d/yyyy h:mm:ss tt') #");

答案 1 :(得分:0)

下面的一个正在工作

columns.Bound(c => c.Column0).Title("Date and Time").Format("{0: dd/MM/yyyy HH:mm}").Width(150);

您可以参考Kendo Grid Automatically changing Timezone