kendo ui mvc网格编辑器模板问题 [英] kendo ui mvc grid editortemplate issue

查看:23
本文介绍了kendo ui mvc网格编辑器模板问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么:

  1. 我在页面的前半部分有一个带有 Kendo UI 控件的表单,例如 DatePicker(s)、Dropdownlist(s)、NumericTextBox(s)

  1. I have a form with Kendo UI controls like DatePicker(s), Dropdownlist(s), NumericTextBox(s) on the first half of the page

后半部分有一个 Kendo UI MVC Grid 控件

Second half has a Kendo UI MVC Grid control

  • 这个 Kendo UI Grid 控件有 8 列,其中 2 列有一个 Kendo 下拉列表 (EditorTemplate) 和 CheckBox(EditorTemplate).
  • Kendo UI Grid 控件是 Ajax 绑定.

单击保存按钮时,来自 Kendo UI 控件(前半部分)和 Kendo UI 网格控件(后半部分)的所有值一起作为 Json 对象通过Ajax Post"发布到控制器.

When the save button is clicked, all the values from the Kendo UI controls(first half) and Kendo UI grid control(second half) together are posted as a Json object via "Ajax Post" to the controller.

我正在为上述过程使用模型绑定

I am using Model binding for the above process

问题或我面临的问题:

带有其他 Kendo UI 控件的表单的前半部分正在正确地将它们的值发布到控制器,但是由于 Kendo UI Grid 在发布某些列值时遇到了一些问题

The first half of the form with other Kendo UI controls are posting their values properly to the controller, but where as the Kendo UI Grid is having some problems posting some column values

  • Kendo UI Grid 中数据类型为小数的列未发布值

  • The columns in the Kendo UI Grid with the datatype decimal is not posting the values

EditorTemplate 控件(如 CheckBox 和 kendo 下拉菜单)在选中时会显示下拉列表的值 "[Object Object]" 和布尔值的实际值,而不是复选框控件.

The EditorTemplate controls like the CheckBox and the kendo dropdown when selected shows the values "[Object Object]" for dropdownlist and the actual value of the boolean rather than the checkbox control.

推荐答案

我怀疑您是否希望将 Grid 作为表单的一部分.通常,网格通过 ajax 进行交互,而不是通过与其他控件一起提交的批处理表单 - 从表单中解开它.仅此一项就可以让您头疼.

I doubt you want the Grid as part of the Form. Typically the Grid interacts via ajax and not via a batch Form submit with other controls - unwrap it from the Form. This alone may save you a headache.

上半场:

尝试使用 Kendo().DatePickerFor()、Kendo().DropDownListFor() 等.您不需要通过 .Name() 显式命名这些 Kendo 控件.这将帮助您进行模型绑定.

Try to use Kendo().DatePickerFor(), Kendo().DropDownListFor(), etc. You do not need to explicitly name these Kendo controls via .Name(). This will help you with the model binding.

下半场:

使用十进制以外的其他数据类型.你觉得这很难吗?尝试使用 TimeSpan 类型来表示没有附加日期的时间(成年男子会哭).

Use another data type other than decimal. You think that is tough? Try using a TimeSpan type for time-of-day with no date attached (grown men cry).

您通常不需要用于布尔值/复选框的 EditorTemplate.只需使用这个技巧(假设您使用的是 Razor,因为您没有留下任何代码).

You do not need, typically, an EditorTemplate for boolean/checkboxes. Just use this trick (asuming your are using Razor, since you left no code).

columns.Bound(b => b.IsActive).ClientTemplate("<input type='checkbox' ${ IsActive == true ? checked='checked' : ''} disabled />");

您的 Grid DDL 最好的选择是

Your best bet for your Grid DDLs is

columns.ForeignKey(b => b.CustodianIdPrimary, Model.Custodians, "Id", "FullName").EditorViewData(new {ProjectId = Model.ProjectId}).EditorTemplateName("CustodianDropDownList");

Model.Custodians 是所有可能项目的列表.然后,您可以将 EditorTemplate 绑定到此列表,或者如果您需要此特定 DDL 中的子集,则进行 ajax 调用以进行填充,如下所示

Where the Model.Custodians is a List of all possible items. You can then bind your EditorTemplate to this List, or make an ajax call to populate if you need a subset in this particular DDL, like this

@model int
@(Html.Kendo().DropDownList()
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
    .DataValueField("Id")
    .DataTextField("FullName")
    .OptionLabel("Unassigned")
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("ReadProjectCustodiansDdl", "SysMaint", new {projectId = ViewData["ProjectId"]}))
    )
)

但这里是剑道提供的例子

But here is the Kendo supplied example

@model object       
@(
    Html.Kendo().DropDownListFor(m => m)        
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
)

请注意在我的初始列中使用 EditorViewData 参数.ForeignKey,在此示例中用于传递整个列表.

Note the use of the EditorViewData parameter in my initial columns.ForeignKey, that is used in this eample to pass the whole list.

祝你好运!

这篇关于kendo ui mvc网格编辑器模板问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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