【问题标题】:Ajax bound Telerik MVC UI Grid not using DisplayTemplateAjax 绑定 Telerik MVC UI Grid 不使用 DisplayTemplate
【发布时间】:2014-12-16 09:11:35
【问题描述】:

如何让 Ajax Bound Telerik MVC UI Grid 显示格式或来自显示模板的任何其他内容?

查看他们的示例here,我看到网格显示带有货币符号的“单价”列。查看下面的 Razor 代码,我看到网格是 ajax 绑定的。不幸的是,我们看不到 ViewModel,但“单价”属性不能是已经格式化的字符串,因为单击编辑按钮会显示一个数字文本框。我创建了 EditorTemplates 和 DisplayTemplates 并且不知何故只有编辑器模板在工作。

我的 ViewModel 看起来像这样:

[UIHint("MoneyTemplate")]
public decimal ItemPrice { get; set; }

其中 MoneyTemplate 分别是显示和编辑器模板 Views/Shared/DisplayTemplates/MoneyTemplate.cshtml 和 Views/Shared/EditorTemplates/MoneyTemplate.cshtml 的名称

当网格出现时,显示模板没有被选中,但编辑器模板是?!?看起来像这样

他们如何在没有客户端模板的情况下显示货币符号?为什么我的显示模板没有被拾取?

【问题讨论】:

    标签: razor telerik kendo-grid kendo-asp.net-mvc display-templates


    【解决方案1】:

    看完这个documentation我发现答案是使用DisplayFormat属性:

    [UIHint("MoneyTemplate")]
    [DisplayFormat(DataFormatString = "{0:C}")]
    public decimal ItemPrice { get; set; }
    

    这将导致网格将小数显示为货币,并使用“MoneyTemplate”编辑器模板进行编辑。

    【讨论】:

      猜你喜欢
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多