是什么决定了Telerik MVC网格中网格列的类型



我的列定义如下:

columns。Bound(o=>o.SequenceNumber)。Title("Seq#")。Width(50)。ClientTemplate("'value='<#=SequenceNumber#>'/>");

我引入的模型将SequenceNumber定义为Nullable<decimal>。当我拉入网格的属性时,Type是"数字"。通常,这是指我们程序中的整数。我知道"Decimal"是Type的有效值。如何使我的数据列显示为Type

Telerik控件进行一些基本反射以匹配适当的编辑器。Nullable<decimal>似乎与数字编辑器不匹配(测试版本2015.1.318)。

相反,您将希望提供它知道要检查的更通用的属性:

// This assumes you have the editor templates added
// to your  ~/Views/Shared/EditorTemplates folder.
[UIHint("Number")]
[DisplayFormat(DataFormatString = "0.00")]
public Nullable<decimal> SequenceNumber { get; set; }

您也可以将[DataType]用于货币类型。

[DataType(DataType.Currency)]
public Nullable<decimal> Amount{ get; set; }

编辑-

测试了另一种方法,在~/Views/Shared/EditorTemplates:中添加了一个名为Decimal.cshtml的新EditorTemplate

@model decimal?
@(Html.Kendo().NumericTextBoxFor(m => m)) 

网格会在SequenceNumber上没有其他属性的情况下按预期找到它。

此时,我的解决方案是在检索该网格的列以进行导出时手动更改该列的数据类型,因为我建议数据类型的尝试失败了。

最新更新