asp.net core – How to set KendoComboBox( jquery UI) value with ViewModel value?

asp.net core – How to set KendoComboBox( jquery UI) value with ViewModel value?

You can set it with the value of KendoComboBox. For example:

$(#test).kendoComboBox({
    dataTextField: text,
    dataValueField: value,
    dataSource: [
        { text: , value: 1 },
        { text: , value: 2 },
        { text: , value: 3 },
    ],
    filter: contains,
    suggest: true,
    index: -1,
    value: @Model.yourValue
});

Use .Value(model), see example below. Polyester will be the selected value.

@(Html.Kendo().ComboBox()
      .Name(fabric)
      .Filter(contains)
      .Placeholder(Select fabric...)
      .DataTextField(Text)
      .DataValueField(Value)
      .Value(2)
      .BindTo(new List<SelectListItem>() {
          new SelectListItem() {
            Text = Cotton, Value = 1
          },
          new SelectListItem() {
            Text = Polyester, Value = 2
          },
          new SelectListItem() {
            Text = Cotton/Polyester, Value = 3
          }
      })
      .Suggest(true)
      .HtmlAttributes(new { style=width:100%; })
)

asp.net core – How to set KendoComboBox( jquery UI) value with ViewModel value?

Leave a Reply

Your email address will not be published.