0

I followed this article for a simple CRUD operation with MVC.

I binded edit button click as suggested in that article, like

$(".editDialog").live("click", function (e) {
        var url = $(this).attr('href');
        $("#dialog-edit").dialog({
            title: 'Edit Employee Detail',
            autoOpen: false,
            resizable: false,
            height: 455,
            width: 550,
            show: { effect: 'drop', direction: "up" },
            modal: true,
            draggable: true,
            open: function (event, ui) {
                $(this).load(url);

            },
            close: function (event, ui) {
                $(this).dialog('close');
            }
        });

        $("#dialog-edit").dialog('open');
        return false;
    }); 

but, when I click on the edit button, its calling the controller action only once, when I click on that for second time, same info which was loaded while the page load is coming again.

I need to call the controller action, each time when I click on edit button. Can any one help me in this. Thanks in advance.

tereško
  • 58,060
  • 25
  • 98
  • 150
shanish
  • 1,964
  • 12
  • 35
  • 62

1 Answers1

0

I think it is doing because your controller's data has been cached by jQuery UI dialog and you are making that dialog again and again on each click of edit button. So probably you should need to destroy this dialog once it has been closed.

Example:

$(".editDialog").live("click", function (e) {
    var url = $(this).attr('href');
    $("#dialog-edit").dialog({
        // your exsiting options
        close: function (event, ui) {
            $(this).dialog('close');
            $(this).dialog('destroy'); // destroy the current dialog
        }
    });

    $("#dialog-edit").dialog('open');
    return false;
}); 

Hope this will fix your issue.

Kundan Singh Chouhan
  • 13,952
  • 4
  • 27
  • 32
  • Thanks for your response. When I call dialog close and destroy as you suggested, am getting error like `0x800a139e - JavaScript runtime error: cannot call methods on dialog prior to initialization; attempted to call method 'close'`. And also, I wont click on modal close button, I will be showing another view in the modal, and when I save that form I will redirect to the current view. – shanish Aug 09 '14 at 07:35