带有数据注释的 KendoUI 网格默认值 [英] KendoUI Grid Default Value with Data Annotation

查看:26
本文介绍了带有数据注释的 KendoUI 网格默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Kendo UI Grid 与 ASP.NET MVC Helpers 和自动生成的列一起使用.

I am using Kendo UI Grid with ASP.NET MVC Helpers and auto generated columns.

我的视图模型中有 [DefaultValue(60 * 60)] 注释,但 Kendo 助手似乎不尊重这一点.

I have [DefaultValue(60 * 60)] annotation in my view model but Kendo helpers doesn't seem to respect that.

是否可以指定默认值(可能带有数据注释)而无需手动描述列?

Can I have default value specified (probably with data annotations) without having to manually describe the columns?

推荐答案

如果你手动定义了网格中的列,不管你是否在注释中定义了默认值,你都需要像这样设置默认值

if you defined the columns in the grid manually, you need to set the default value like this despite you defined the default value in the annotation or not

 @(Html.Kendo()
      .Grid()
      .DataSource( d=> d.Ajax()
                        .Model(m=>{
                            m.Field(f=>f.YourField).DefaultValue(YourValue);
                 }))
)

因此对于自动生成的列,您可以尝试以下操作

so for the auto-generated columns you can try the following

@(Html.Kendo()
      .Grid()
      .Events( e => e.Edit("onEdit"))
)

<script type="text/javascript">
      function onEdit(e) {   
           //check if record is new
           if (e.model.isNew()) {
                // set the value of the model property like this                    
                e.model.set("PropertyName", Value);
                // for setting all fields, you can loop on 
                // the grid columns names and set the field
           }
    }
</script>

希望对你有帮助

这篇关于带有数据注释的 KendoUI 网格默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆