簡體   English   中英

從Ajax數據綁定創建的下拉列表中的數據

[英]Binding data in created dropdown from ajax data

我在cshtml頁面中創建了以下下拉列表:

@(  Html.Kendo().DropDownList().Name("ddlCode").OptionLabel("Select Code...").BindTo(@ViewBag.dropDown)
            .DataTextField("Title")
            .DataValueField("domainCode")

我在檢查頁面上的復選框之一時綁定了此下拉列表。

在檢查復選框時,我調用了javascript函數並編寫了如下的ajax腳本:

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 () {
                    //
                }
            });

PPController的BindDropdown包含以下代碼:

public JsonResult BindDropDown(string ID)
        {
            List<TEAMS_PP.Entity.correlations> list = new correlation().getDropDownvalues(ID);
            ViewBag.dropDown = list;
            return Json(list);
        }

我的問題是,當下拉列表綁定時,它的項目顯示為“ Undefined ”,如下所示:

在此處輸入圖片說明

我如何綁定此下拉菜單???

我正在使用MVC4 Kendo UI控件

Entity.Correlations:

   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;
    }
}

發生的是在這里...

@(Html.Kendo().DropDownList().Name("ddlCode").OptionLabel("Select Code...").BindTo(@ViewBag.dropDown)
        .DataTextField("Title")
        .DataValueField("domainCode")

您正在告訴DropDownListcorrelations類中找到TitledomainCode屬性。 但是, correlations類不具有此類屬性。

要使此工作,您必須執行以下任一操作:

  1. TitledomainCode屬性添加到correlations
  2. 使用其他模型對象公開此屬性,以便下拉列表可以與其綁定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM