如何在 ASP.NET MVC 框架中通过调用 ajax 来显示 kendoDropDownList?

问题描述

我有一个剑道 kendoDropDownList。我正在尝试通过调用 Ajax 来填充下拉值。不幸的是,每次我单击下拉菜单时,它都会调用 Action 并返回值,但下拉列表不显示列表。我用一个简单的字典测试了几次,它对测试数据(显示在代码中)工作正常,但是当我用真实数据填充相同的数据时,它没有显示下拉值。如果我做错了什么,你能看看吗?

操作:

public ActionResult SubmitterActionTypes(int id)
        {
            var types = ServiceProvider.SupplementalDataService.SubmitterActionTypes()
                .OrderBy(x => x.Name);

   
            Dictionary<int,string> typesDic = new Dictionary<int,string>();

            // Following Test code works fine and drop down populates with values...
            /*typesDic.Add(1,"Item 1");
            typesDic.Add(2,"Item 2");
            typesDic.Add(3,"Item 3");
            typesDic.Add(4,"Item 4");*/

            // Following code does not work and dropdown does not show any result
            foreach(var type in types)
            {
                if (type.Name!=null && type.Name != "None")
                {
                    typesDic.Add(Convert.ToInt32(type.SubmitterActionRequiredTypeID),type.Name.ToString());
                }
            }

            return PartialView("JsonResult",typesDic.ToList()); 
        }

阿贾克斯:

var submitterActionRequired = $("#submitterActionRequired").kendoDropDownList({
        optionLabel: "Select User Assignee...",dataTextField: "Value",dataValueField: "Key",height: 310,Width: "900px",dataSource: {
            transport: {
                read: function (options) {
                    $.ajax({
                        url: "/Submission/SubmitterActionTypes",dataType: "JSON",data: {
                            id: EntityOrganizationID
                        },success: function (result) {
                            // notify the data source that the request succeeded
                            options.success(result);
                        },error: function (result) {
                            // notify the data source that the request failed
                            options.error(result);
                        }
                    });
                }
            }
        }
    }).data("kendoDropDownList");

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)