Question

i have a jquery dialog, where i load a two partialview, a simple master/detail when i come back to master after save the detail, click button not response.

i post some code:

MASTER

        $('#dialogActivities').dialog({
        autoOpen: false,
        open: function (event, ui) {
            var id = $(this).data('id');
            var urlList = '@Url.Action("ActivityList", "Contacts")';

            $(this).load(urlList, function ()
            {
                $(".k-grid-ActivityEdit").bind("click", function ()
                {
                    var grid = $("#gridYear").data("kendoGrid");
                    var selectedData = grid.dataItem(grid.select());
                    if (selectedData)
                    {
                        var urlEdit = '@Url.Action("ActivityEdit", "Contacts")';
                        $('#dialogActivities').dialog().load(urlEdit);
                    }
                });
            });
        }
    });

DETAIL

$(document).on('submit', '#frmActivityEdit', function ()
{
    $.ajax({
        cache: false,
        url: this.action,
        type: this.method,
        data: $(this).serialize(),
        success: function (result)
        {
            if (result.success)
            {
                var model = @Html.Raw(Json.Encode(Model));
                var urlList = '@Url.Action("ActivityList", "Contacts")';

                $('#dialogActivities').dialog().load(urlList);
            }
        }
    });
    return false;
});
Was it helpful?

Solution

Please try to replace this piece of code:

$(".k-grid-ActivityEdit").bind("click", function ()
            {
                var grid = $("#gridYear").data("kendoGrid");
                var selectedData = grid.dataItem(grid.select());
                if (selectedData)
                {
                    var urlEdit = '@Url.Action("ActivityEdit", "Contacts")';
                    $('#dialogActivities').dialog().load(urlEdit);
                }
            });

With this one:

$(document).on("click", ".k-grid-ActivityEdit", function ()
            {
                var grid = $("#gridYear").data("kendoGrid");
                var selectedData = grid.dataItem(grid.select());
                if (selectedData)
                {
                    var urlEdit = '@Url.Action("ActivityEdit", "Contacts")';
                    $('#dialogActivities').dialog().load(urlEdit);
                }
            });

The difference is that using on function to bindning works also for dynamically added elements. It can resolve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top