如何在 ASP.NET MVC 框架中通过调用 ajax 来显示 kendoDropDownList? [英] How to display kendoDropDownList by calling ajax in ASP.NET MVC framework?

查看:26
本文介绍了如何在 ASP.NET MVC 框架中通过调用 ajax 来显示 kendoDropDownList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've a Kendo kendoDropDownList. I'm trying to populate drop down values by calling Ajax. Unfortunately every time I click the drop down it calls the Action and it returns the values but dropdown does not display list. I tested several times with a simple Dictionary and it works fine with test data (Shown in code) but when I populate the same with real data it's not showing drop down values. Can you please take a look If I'm doing anything wrong?

操作:

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");

推荐答案

我觉得actionResult的返回类型应该是这样的:

I think the return type of the actionResult should be like this:

返回 Json(assignes)

return Json(assignes)

此上下文中的 PartailView 不起作用.

The PartailView in this Context doesn't work.

这篇关于如何在 ASP.NET MVC 框架中通过调用 ajax 来显示 kendoDropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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