简体   繁体   English

Kendo Jquery 外键下拉列表值

[英]Kendo Jquery ForeignKey Dropdownlist values

My application is MVC 5, using Kendo UI Jquery editable grid.我的应用程序是 MVC 5,使用 Kendo UI Jquery 可编辑网格。 One of the column is a dropdownlist using:其中一列是下拉列表,使用:

{ field: "ApplicableCourse_ID", title :"Course", values: myDDL1 }

I use the following Ajax to generate the values array myDDL1我使用以下 Ajax 生成值数组myDDL1

$.ajax({
        url:  '@Url.Action("GetFreeAccessDropdownList", "fff")',
        type: "GET",
        async: false,
        cache: false,
        dataType: "json",
        success: function (result) {
            myDDL1.push(JSON.stringify(result.Grid1));
           var grid = $("#grid").data("kendoGrid");
            grid.refresh();
        },
        error: function (request, status, error) {
            alert(request.responseText);
        }
    });

I get the correct value and text:我得到正确的值和文本: 在此处输入图像描述

However;然而; the grid show the value instead of the text.网格显示值而不是文本。 If I use static array:如果我使用 static 数组:

var myDDL1 = [
        { "value": 54, "text": "Fuel Spill Response Plan" },
        { "value": 56, "text": "Community Fuel Contractor Manual" },
        { "value": 91, "text": "Blocking and Cribbing" }];

The correct text is displayed.显示正确的文本。 Is there a difference between dynamic array and static array?动态数组和static数组有区别吗?

Calling the refresh() method of the grid after populating the collection would be insufficient as it would not refresh the templates and the foreign key column.在填充集合后调用网格的 refresh() 方法是不够的,因为它不会刷新模板和外键列。

There are two options:有两种选择:

  1. Make the AJAX call directly from the column and there is no need for handing the success callback:直接从列中调用 AJAX,无需处理成功回调:

Remote data binding for foreign key 外键的远程数据绑定

  1. Set the autoBind property of the grid to false.将网格的autoBind 属性设置为 false。 Inside the success callback of your custom AJAX, call the fetch() method of the data source of the grid.在自定义 AJAX 的成功回调中,调用网格数据源的fetch() 方法

Just in case someone else has this problem;以防万一其他人有这个问题; the solution I used was to generate in the controller a ViewBag of the list:我使用的解决方案是在 controller 中生成一个 ViewBag 列表:

var grid1 = db.Courses.Select(c => new
            {
                value = c.ID,
                text = c.Name,
            }).ToList();
            ViewBag.Course = grid1;

In the view在视图中

var myDDL1 = @Html.Raw(Json.Encode(ViewBag.Course));

The Grid column网格列

field: "ApplicableCourse_ID", filterable: { multi: true, search: true }, values: myDDL1 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM