0

次の問題があります: telerik mvc グリッドのカスタム編集コマンドがあります。これはグリッドのコードです:

Html.Telerik().Grid<Customer>("customers")
                       .Name("Grid")
                       .DataKeys(k => k.Add(o => o.Id))
                       .DataBinding(dataBinding => dataBinding.Ajax().Delete("Delete", "Customer").Select("AjaxIndex", "Customer"))
                       .Scrollable(builder => builder.Height(350))
                       .Filterable()
                       .Sortable(s => s.OrderBy(order => order.Add(o => o.Id).Descending()))
                       .Columns(c =>
                                 {
                                     c.Bound(o => o.Id);
                                     c.Bound(o => o.FirstName);
                                     c.Command(s =>
                                                   {
                                                       s.Custom("editCustomer")
                                                           .Text("Edit")
                                                           .Ajax(true)
                                                           .Action("Edit", "Customer");
                                                            s.Delete().ButtonType(GridButtonType.Image);                                                                                                                }).Width(175);
                                 })
               .ClientEvents(builder => builder.OnComplete("onEditComplete"))
                   .Pageable(p => p.PageSize(5))
                   .Selectable()
                   .Render();

これは、編集コマンドのコールバック JavaScript 関数です。

function onAppraisalPhaseComplete(e)
{
    if (e.name == "editCustomer") {
        $("#dialog-form").html(e.response.PartialViewHtml);
        open($("#dialog-form"), "Edit Customer"); // this will display a modal with the edit view
    }
}

編集フォームは、次のメソッドへの ajax 呼び出しです。

    public ActionResult JsonEdit(Customer customer)
    {
        if ((Rules.GetBrokenRules(customer).Count == 0))// there is no validation errors
        {
            Repository.Update(customer);
        }
        else
        {
            ModelState.AddModelErrors(Rules.GetBrokenRules(customer));
            return Json(new
            {
                Success = false,
                PartialViewHtml = RenderPartialViewToString("Insert", appraisalPhaseViewModel)
            });
        }
//if save successful get the customers list and return the partial of the grid in Json
        var customers= Repository.GetAll().ToList();
        ViewData["customers"] = customers;

        return Json(new
        {
            Success = true,
            PartialViewHtml = RenderPartialViewToString("MasterGrid")
        });

完了時の ajax 呼び出しは次のとおりです。

 function JsonSave_OnComplete(context) {
        var jsonEdit = context.get_response().get_object();
        if (jsonEdit.Success) { // if the operation is successful reload grid and close the modal dialog
            $("#MasterGridDiv").html(jsonEdit.PartialViewHtml);
            CloseDialog($('#dialog-form'));
        } else { //Redisplay the edit partial view in the modal
            $("#dialog-form").html(jsonEdit.PartialViewHtml);
        }
    }

編集操作が終了した後、削除ボタンを押そうとすると、削除操作の代わりに JsonEdit アクションが呼び出されます。ここで何が間違っているのかわかりませんか?さらに、削除ボタンが機能せず、削除ボタンの代わりに ajax バインディングが呼び出されることがあります。

4

1 に答える 1

2

ボタン用の完全な JavaScript ハンドラーを提供していませんでした。コールバックのみを提供していました。私はあなたがそれを正しくやったと仮定すべきです。ただし、コードには明らかな問題があります。サーバー側のレンダリングされたビューから html を挿入することにより、テレリック グリッドを手動で再バインドしようとしています。これにより、クライアント イベント モデルが予期せずハイブする可能性があります。それ以外の :

$("#MasterGridDiv").html(jsonEdit.PartialViewHtml);

使用してみてください:

 $("#Grid").data("tGrid").rebind();
于 2012-08-14T14:13:55.167 に答える