首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ajax数据创建下拉列表中的数据绑定

从ajax数据创建下拉列表中的数据绑定
EN

Stack Overflow用户
提问于 2014-06-10 05:38:01
回答 1查看 84关注 0票数 0

我在cshtml页面中创建了以下下拉列表:

代码语言:javascript
复制
@(  Html.Kendo().DropDownList().Name("ddlCode").OptionLabel("Select Code...").BindTo(@ViewBag.dropDown)
            .DataTextField("Title")
            .DataValueField("domainCode")

我正在绑定此下拉列表,以检查我页面上的一个复选框。

在检查复选框时,我调用了javascript函数并编写了如下ajax脚本:

代码语言:javascript
复制
var ddl = $('#ddlCode').data("kendoDropDownList");
            $.ajax({
                url: "/PP/BindDropDown",
                data: {
                    'Id': paramID
                },
                dataType: "json",
                type: 'POST',
                cache: false,
                success: function (_data) {

                    ddl.dataSource.data(_data)

                },
                error: function () {
                    //
                }
            });

BindDropdown of PPController包含如下代码:

代码语言:javascript
复制
public JsonResult BindDropDown(string ID)
        {
            List<TEAMS_PP.Entity.correlations> list = new correlation().getDropDownvalues(ID);
            ViewBag.dropDown = list;
            return Json(list);
        }

我的问题是,当下拉列表被绑定时,它将其项显示为"Undefined“,如下所示:

我怎么才能把这个下拉包绑起来?

我使用的是MVC4 Kendo控件。

Entity.Correlations:

代码语言:javascript
复制
   public correlations() { }

    public correlations(DB.EH_PP_DmainComp item)
    {
        //this.code = Convert.ToInt32( Convert.ToString(item.domainCode));
        this.correlatedText = item.description;
        this.codeTitle = item.title;
        //Component 1a: Demonstrating Knowledge of Content and Pedagogy
        //ArrayList arrCode = new ArrayList();
        string[] arrCode = Convert.ToString(item.title).Split(':');

        string[] code = Convert.ToString(arrCode[0]).Split(' ');
        this.code = Convert.ToString(code[1]);

    }

    public DB.EH_PP_DmainComp ToDB()
    {
        var rec = new DB.EH_PP_DmainComp();

        return rec;
    }

    public DB.EH_PP_DmainComp ToDB(DB.EH_PP_DmainComp rec)
    {

        return rec;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-10 05:52:06

这里发生的是..。

代码语言:javascript
复制
@(Html.Kendo().DropDownList().Name("ddlCode").OptionLabel("Select Code...").BindTo(@ViewBag.dropDown)
        .DataTextField("Title")
        .DataValueField("domainCode")

您正在告诉DropDownListcorrelations类中找到TitledomainCode属性。但是,correlations类没有这样的属性。

要完成这项工作,您必须做以下工作之一:

  1. TitledomainCode属性添加到correlations
  2. 使用公开此属性的另一个模型对象,以便下拉列表可以绑定到它。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24133622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档