1

View(model) is returned from a controller IActionResult method, but Kendo combo-box selected value is not get reflected like other UI elements.

How can I set the selected value of the combo-box with the View model value?

DaminiVyas
  • 308
  • 3
  • 15

2 Answers2

2

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'
});
Fateme Mirjalili
  • 762
  • 7
  • 16
  • 1
    as I was using JqueryUI to set up the combo-box, this answer actually solves the issue. Thanks @Fateme for the answer! – DaminiVyas Jun 22 '20 at 13:44
1

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%;" })
)
Rico Koldi
  • 376
  • 2
  • 10