Kendo MultiSelect无法读取属性'值'

Kendo MultiSelect Cannot read property 'value'

本文关键字:属性 读取 MultiSelect Kendo      更新时间:2023-09-26

这是我的PartialView:

.......
        <div class="form-group">
            @Html.LabelFor(model => model.securities, htmlAttributes: new { @class = "control-label col-md-2"})
            <div class="col-md-10">
       @(Html.Kendo().MultiSelect()
         .Name("productMultiSelect")
         .DataTextField("label")
         .DataValueField("value")Product to be used by the multiselect as a value.
         .HtmlAttributes(new { style = "width:350px; height:350px", @id = "prd" })
         .Filter(FilterType.Contains)
        .DataSource(source =>
         {
             source.Read(read =>
             {
                 read.Action("GetLogin", "IT_Inventory");
             })
             .ServerFiltering(false);
         })
        .Value(ViewBag.SelectedItem2)
        .ItemTemplate("<span><h3 style='"font-size: 1.2em;font-weight: normal;margin: 0 0 1px 0;padding: 0;'">#: data.label #</h3><p style='"margin:0;padding:0;font-size: .8em; '">#: data.desc #</p></span>")  
                )
            </div>
        </div>

我的按钮:

<button type="button" id="btnSave" class="btn btn-success btn-lg">Save </button>

我的JS:

<script>
    $("#btnSave").click(function (e) {
        e.preventdefault();
        $.ajax({
            type: 'POST',
            url: '@Url.Action("SignIT", "IT_Inventory")',
            data: JSON.stringify({ productMultiSelect: $("#productMultiSelect").data("kendoMultiSelect").value(), id: $("#id").val(), SomeBooleanProperty: false }),
            dataType: 'json',
            contentType: 'application/json',
            success: function (data) {
                if (data == true) {
                    $("#onInsert").data("kendoWindow").close();
                }
                else {
                    alert("Error!");
                }
            },
            error: function () {
                alert("An error has occured!!!");
            }
        });
    });
</script>

当我尝试张贴到控制器时,我得到了Uncaught TypeError: Cannot read property 'value' of undefined。对于id和SomeBooleanProperty是可以的。当我使用提交表格是可以的。我应该将数据发布到产品的控制器列表MultiSelect?

看起来您还没有初始化kendoMultiSelect,或者它在另一个div中;

查看:

console.log($("#productMultiSelect").length); //should be at least 1, if 0, then you initialized kendo in come other div

console.log($("#productMultiSelect").data("kendoMultiSelect")); //should be an object - if undefined, then you have not initialized kendo 
console.log($("#productMultiSelect").length); - 0
console.log($("#productMultiSelect").data("kendoMultiSelect")); - undefined

非常有趣和奇怪。

此PartialView位于KendoWindow中。