i am using Kendo DropdownList with ajax binding.
With these codes i cannot set inital value that coming from model.It just fill the list with items and selects the first item.
@(Html.Kendo().DropDownList()
.Name("NATIONALITY")
.DataTextField("DESCRIPTION").HtmlAttributes(new { style = "width:220px" })
.DataValueField("REFERENCEID")
.Value(Model.NATIONALITY)
//Placeholder("SELECT")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetDefinitionDetails", "Definition", new { definitionCode = "NATIONALITY", addEmptyRow = false });
}).ServerFiltering(true);
}).ServerFiltering(true);
}))
But When i change Html.Kendo().DropDownList() to Html.Kendo().Combobox() it also fills the list and set the initial value as expected(which is the value that passing by model.)
On the Kendo DropDownList
you can specify the SelectedIndex
as follows:
@(Html.Kendo().DropDownList().SelectedIndex(myIndex)
.//other builder stuff
With the DropDownList
you can only specify the index of the item that is to be selected. You cannot chose this item by its text.
Using the client-side API you can set set selected value based on the text, by using the value method. Just add an event on the data bound that calls a JavaScript function. This function can then select the desired item based on its text.
With the latest(maybe works on earlier versions) build of KendoUI , initial Text value can be set on dropdowns:
....
.Value(Model.DOCTORCODE.ToString()) //DOCTORCODE is guid type
.Text(Model.DOCTOR) //DOCTOR is string type.This is optional.It should work without .Text property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With