【问题标题】:Kendo UI Multiselect post data is not coming, list count=0剑道 UI 多选帖子数据未到来,列表计数 = 0
【发布时间】:2014-04-08 18:12:35
【问题描述】:

我无法在控制器中获得 Kendo UI Multiselect 的值。它给我的列表长度为 0。MultiSelect 为:

@(Html.Kendo().MultiSelectFor(model => model.Technicians)
                            .Name("Technicians")
                            .Placeholder("Select Technician(s)")
                            .DataTextField("Name")
                            .DataValueField("ID")
                            .Filter(FilterType.Contains)
                            .AutoBind(true)
                            .DataSource(source =>
                            {
                                source.Read(read =>
                                {
                                    read.Action("GetTechnicians", "Project");
                                })
                                .ServerFiltering(false);
                            })
                            .BindTo(Model.Technicians)          
                        )

技术员是:公开名单技术员{get;设置;} 在模型中

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    我也遇到过这个问题。

    我们最终在视图模型中创建了一个 IEnumerable<int> 的 Id 来存储该值。

    所以,在我们的例子中

    public IEnumerable<PersonLookupViewModel> TaggedPersons { get; set; }(这是我真正想要的具有 ID 的人员列表 - 包含 first/last/id)

    public IEnumerable<int> PeopleToTag { get; set; }(这是视图模型的 IEnumerable Int,仅用于将 int 发布到控制器)

    我的观点是这样的:

    <div class="editor-field">       
      @Html.LabelFor(model => model.taggedPersons)
      @Html.ListBoxFor(model => model.PeopleToTag, 
         new SelectList(Model.CommitteeMembers, "PersonId", "FullName"))                  
    </div>
    

    JS 连接起来

    $("#PeopleToTag").kendoMultiSelect({ "dataTextField": "FullName", "dataValueField": "PersonId", "placeholder": "Tag or Untag Persons to Action Item" });
    

    因此将其切换到 ListBoxFor(model = > model.PeopleToTag) 这是我的视图模型中的 Ienumerable 字段,只是为了能够在控制器中获取数据。然后我使用 automapper 创建了我真正需要的 Person 模型。

    我不确定这是否是最好的方式,但它对我们有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多