2016-07-02 12 views
2

Es ist mein PartialView:Kendo Multiselect kann nicht lesen Eigenschaft 'Wert'

....... 

     <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> 

Meine Taste:

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

Mein 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> 

Wenn ich Post versuche ich den Controller bekomme ich Uncaught TypeError: Cannot read property 'value' of undefined. Für ID und SomeBooleanProperty ist ok. Wenn ich einreichen Formular ist in Ordnung. Ich sollte Daten in der Controller-Liste von productMultiSelect veröffentlichen?

+0

versuchen Sie, Ihre js-Funktion in '.ready()' einzufügen. Könnte sein, dass der Listener hinzugefügt wird, bevor Multiselect initialisiert wird –

Antwort

0

Sieht so aus, als hättest du KendoMultiSelect nicht initialisiert, oder es ist in einem anderen div;

Überprüfen Sie es:

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

und

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

Danke. Meine MultiSelect ID ist "prd". – MinSIL

0
console.log($("#productMultiSelect").length); - 0 
console.log($("#productMultiSelect").data("kendoMultiSelect")); - undefined 

sehr interessant und seltsam.

Diese PartialView ist in KendoWindow.

Verwandte Themen