Question

I am using a kendo UI DropDownList control, how can we set a default value to the DropDownList?

I have a selected list property in viewmodel as following :

public SelectList AuditTypes { get; set; }

Then in controller I am populating the selected list and setting it to a default value

viewModel.AuditTypes = new SelectList(dropdownDetails, "Value", "Text", dropdownDetails.Where(x => x.Default == true));

and in my razor view I have the following code :

  @(Html.Kendo().DropDownList()
                    .Name("AuditType")
                    .DataTextField("Text")
                    .DataValueField("Value")
                    .BindTo(Model.AuditTypes)                     
                    .AutoBind(true)

The problem is that the default value is not being set.

Was it helpful?

Solution

Just a guess, try .Value(YOUR_VALUE) in your chain

http://docs.kendoui.com/api/web/dropdownlist#configuration-value

Note:- Make sure to pass the ValueField and not the TextField in the .Value() property of Kendo Control as "YOUR_VALUE" has to be an integer property as .Value() accepts an integer and not a text property, otherwise it won't work, it won't show any error but it won't give you the desired result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top