Binding data in created dropdown from ajax data

I have following dropdown created in cshtml page:

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

I am binding this dropdown on checking of oneof the checkbox on my page.

On checking of checkbox i have called javascript function and written ajax script as follows:

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 contains code as:

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

My problem is when dropdown gets bound it shows its items as "Undefined" as below:

How can i bind this dropdown???

I am using MVC4 Kendo UI Controls

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

Answers


What's happening is that here...

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

You are telling the DropDownList to find the Title and the domainCode property in the correlations class. However, the correlations class does NOT have such properties.

To make this work you have to do one of the followings:

  1. Add a Title and domainCode property to the correlations class
  2. Use a different model object that exposes this property so that the dropdown list can bind to it

Need Your Help

Making a web interface to a script that takes 30 minutes to execute

python http-headers timeout http-status-code-504

I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.

Textchange event not working

c# asp.net .net

I am doing a preview of what I am currently typing in a web page using ASP.NET. What I am trying to achieve is that whenever I type or change text in the textbox, the &lt;h3&gt; or label element will

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.