【问题标题】:How to set KendoComboBox( jquery UI) value with ViewModel value?如何使用 ViewModel 值设置 KendoComboBox(jquery UI) 值?
【发布时间】:2020-06-17 08:18:42
【问题描述】:

View(model) 从控制器 IActionResult 方法返回,但 Kendo 组合框选择的值不会像其他 UI 元素那样得到反映。

如何使用视图模型值设置组合框的选定值?

【问题讨论】:

标签: asp.net-core kendo-ui kendo-combobox


【解决方案1】:

您可以使用KendoComboBoxvalue 进行设置。例如:

$("#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'
});

【讨论】:

  • 当我使用 JqueryUI 来设置组合框时,这个答案实际上解决了这个问题。感谢@Fateme 的回答!
【解决方案2】:

使用 .Value(model),参见下面的示例。聚酯将是选定的值。

@(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%;" })
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 2014-02-12
    • 2010-09-22
    相关资源
    最近更新 更多