Kendo UI ASP.net MVC - Why dropdownlist is getting empty data on select event? -
in asp.net mvc view i've kendo dropdownlist , grid. i'm after grid hidden default, based on selection of dropdownlist, grid should populate relevant data , displayed.
however, select event dropdownlist not getting correct data. gets previous selection instead of current selection.
code view is:
@model myapplication.models.customermodel @{ viewbag.title = "customer information"; } <h2>customer information</h2> <div class="container"> <div class="row"> @(html.kendo().dropdownlist() .name("customerid") .optionlabel("select customer") .bindto((list<selectlistitem>)viewbag.customerlist) .datatextfield("text") .datavaluefield("value") .events(e => e.select("onselect")) .htmlattributes(new { @class = "k-textbox large" })) </div> <div class="row"> @(html.kendo().grid<myapplication.models.customermodel>() .name("contractgrid") .columns(columns => { columns.bound(c => c.contractcode).title("contract id").width(240); columns.bound(c => c.contractdescription).title("description").width(240); columns.bound(c => c.contractprice).title("price").width(240); columns.bound(c => c.expirationdate).title("expiration date").width(240).format("{0:mm/dd/yyyy}"); } ) .sortable() .pageable(page => page .refresh(true) .pagesizes(true) ) .datasource(datasource => datasource .ajax() .read(read => read.action("getcontracts", "pricing").data("additionaldatacontracts")) .pagesize(10) ) ) </div> </div> <script> $(document).ready(function () { $("#contractgrid").hide(); }); var ddlitem=null; function additionaldatacontracts(e) { var dataitem = $("#customerid").data("kendodropdownlist").value(); alert("additional data - customer: " + dataitem); return { item: dataitem } } function onselect(e) { ddlitem = this.dataitem(e.item); var dataitem = $("#customerid").data("kendodropdownlist").value(); alert("select: " + dataitem); $("#contractgrid").show(); var gridcontracts = $("#contractgrid").data("kendogrid"); gridcontracts.datasource.read(); } </script>
what doing wrong , how can correct it?
i believe you'll want use change event, seen here.
edit: you're seeing what's previous selection because of call here, within select delegate:
$("#customerid").data("kendodropdownlist").value()
the select
event triggers before element's value set.
Comments
Post a Comment