how to set a default value to kendo ui dropdown?
Asked Answered
G

1

9

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.

Go answered 19/6, 2013 at 5:11 Comment(3)
Can you use DropDownListFor(m => m.AuditTypeId)?Thirsty
That's not really using Kendo though, I am curious as to how to achieve this with KendoGo
KendoUI also has a DropDownListFor(x=>x.value) version, so Longball27's suggestion is valid (and preferable in Razor).Poetics
O
5

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.

Option answered 21/6, 2013 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.