如何将 kendo 下拉列表绑定到模型 属性?

How do you bind a kendo dropdownlist to a model property?

我有一个 kendo 下拉列表,在我看来定义如下:

        @(Html.Kendo().DropDownList()
                .Name("RowCategoryID")
                .OptionLabel("Select Row Category...")
                .BindTo(new SelectList(Model.RowCategories.Select(r => new { Key = r.Key, Value = r.Value }), "Key", "Value"))
                .HtmlAttributes(new { style = "width: 50%" })

我的模型有一个名为 RowCategoriesDictionary<int,string>,它有 key/value 对 DDL。它还有一个名为 RowCategoryIDint 属性 表示当前 RowCategory select 从 RowCategories 列表中删除。

DDL 使用 RowCategories 中的值进行填充,但不会 select 具有 RowCategoryID 值的选项。它只是默认为 "Select Row Category...".

如何得到select值为RowCategoryID的选项?

尝试使用方法 Value():

@(Html.Kendo().DropDownList()
            .Name("RowCategoryID")
            .OptionLabel("Select Row Category...")
            .BindTo(new SelectList(Model.RowCategories.Select(r => new { Key = r.Key, Value = r.Value }), "Key", "Value"))
            .Value(Model.RowCategoryID) // <- this
            .HtmlAttributes(new { style = "width: 50%" })

尽管我在 the documentation, I have spotted it the demos 中找不到该方法(参见 "Basic usage")。