如何在不使用html包装的情况下将视图模型数据绑定到Kendo DropDownlist

How to bind view model data to Kendo DropDownlist without using the html wrapper

本文关键字:模型 视图 数据绑定 DropDownlist Kendo 情况下 包装 html      更新时间:2023-09-26

我正在使用ASP.NET MVC5。视图采用控制器的模型:

    public class IncidentWorkbenchViewModel
    {
        public List<string> ActiveUserList { get; set; }
    }

我想出了如何使用ASP.NET包装器的Kendo UI将列表绑定到Kendo DropDownList,方法如下:

@(Html.Kendo().DropDownListFor(m => m.ActiveUserList)
    .BindTo(Model.ActiveUserList).Name("selectedUser")))

现在我想知道如何在不使用HTML助手的情况下完成同样的操作。我认为使用javascript而不是包装器更好地实现代码分离。

javascript等价物是:

<input id="selectedUser" />
<script>
  var activeUsers= @Html.Raw(Json.Encode(Model.ActiveUserList));
  $("#selectedUser").kendoDropDownList({
    dataSource: activeUsers,
    dataTextField: "Name",
    dataValueField: "Id"
  });
</script>

http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist