Asp.net-Mvc

如何在 kendo.ui.grid 中創建自定義 kendo.ui.Window 以進行編輯

  • August 12, 2013

我是 kendo.Ui 的初學者,我為創建網格編寫此程式碼

@(Html.Kendo().Grid<BrandViewModel>(Model)
   .Name("Grid")
   .Columns(columns =>
   {
       columns.Bound(p => p.BrandName);
       columns.Bound(p => p.BrandAbbr);
       columns.Bound(p => p.SrcImage);

       columns.Command(command => command.Custom("Edit").Click("editItem"));

   })

   .DataSource(dataSource => dataSource
       .Ajax()
       .Read(read => read.Action("CustomCommand_Read", "Brand"))
        .Model(model => model.Id(p => p.Id))

              )
)

我想當使用者點擊在劍道視窗中Edit打開的按鈕時Edit view我編寫此程式碼

@(Html.Kendo().Window().Name("Details")
   .Title("Customer Details")
   .Visible(false)
   .Modal(true)
   .Draggable(true)

   .Width(300)
)



<script type="text/x-kendo-template" id="template">
   <div id="details-container"> <!-- this will be the content of the popup -->
       BrandName: <input type='text' value='#= BrandName #' />

   </div>
</script>

和java腳本程式碼:

<script type="text/javascript">
   var detailsTemplate = kendo.template($("#template").html());

   function editItem(e) {
       e.preventDefault();

       var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

       $("#Details").data("kendoWindow").refresh({
           url: "/Brand/Edit/" + dataItem.Id
       });
       $("#Details").data("kendoWindow").open();



   }
</script>

此程式碼工作正常我第一次點擊一個按鈕,但是當我第二次點擊時。我遇到了以下錯誤

0x800a138f - JavaScript runtime error: Unable to get property 'refresh' of undefined or null reference

請幫助我,謝謝大家

我記得我對這個控制項有類似的問題。現在它適用於我的以下 Javascript 程式碼:

<script type="text/javascript">
   var detailsTemplate = kendo.template($("#template").html());
   var windowObject;

   $(document).ready(function () {
       windowObject = $("#Details").data("kendoWindow");
   });

   function editItem(e) {
       e.preventDefault();

       var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

       windowObject.refresh({
           url: "/Brand/Edit/" + dataItem.Id
       });
       windowObject.open();
   }
</script>

希望能幫助到你 !

引用自:https://stackoverflow.com/questions/18148734