I am using kendoui dropdownlist. I am loading the values in the dropdownlist dynamically. I have written the code like
$("#dropdown").kendoDropDownList({
dataSource:
{
transport: {
read:
{
url: "/Projects/Dropdown",
type: "POST",
dataType: "json"
}
},
},
dataTextField: "type",
dataValueField: "type",
value: "Type2",
});
And in the controller i have defined like:
public ActionResult Dropdown(int projectid, int controlid)
{
var values = Context.controloptions.Where(i => i.id== id).Select(i => new {
type = i.value
}).ToArray();
return Json(values, JsonRequestBehavior.AllowGet);
}
The values will contains an array: [{type="Type1"},{type="Type2"}]
. How can i bind the value of "Type2" by giving the value. I am adding the screen shot of the value that are coming.
Either define the DropDownList
as:
$("#dropdown").kendoDropDownList({
dataSource : {
transport: {
read: {
url : "/Projects/Dropdown",
type : "POST",
dataType: "json"
}
}
},
value: "Type2"
});
or return the data as [{"type":"Type1"},{"type":"Type2"}]
and define the DropDownList
as:
$("#dropdown").kendoDropDownList({
dataSource : {
transport: {
read: {
url : "/Projects/Dropdown",
type : "POST",
dataType: "json"
}
}
},
dataTextField: "type",
dataValueField: "type",
value : "Type2"
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.