views:

30

answers:

1

i am using jquery ui dialog and displaying a form:

$("#detailView").dialog({
    resizable: false,
    height: 'auto',
    autoOpen: false,
    width: 1000,
    modal: true,
    buttons: {
        'Close': function () {
            closeModalPopup();
        }
    }
});

i have a button inside my form (not the dialog buttons). When i click this button, i send ajax to the server using this code below:

 $('.button').live('click', function () {

    $.post('/MyController/Update', $("#myForm").serialize(), function (data) {

        if (data == "Update Complete") {
            closeModalPopup();
        }
        else {
            $("#detailView").html(data);
        }
    }, "html");
});

if the post is successful, i return "Update Complete" which just goes and closes the jquery ui dialog.

the issue is that when it fails and i have an error i do this in my controller action:

        if (!validationResult.IsValid)
        {
            validationResult.AddToModelState(ModelState, null);
            return PartialView("DetailContent", hireRequest);
        }
        else
        {
            return Content("Update Complete");
        }

this should hit the "else" case in the javascript callback and show the new content in the dialog but what seems to be happening is that the content of the partialresult shows up on the full underlying page (as opposed to the modal dialog where i want it)

any suggestions on whats going wrong here?

+1  A: 

You should probably create another container (a DIV for example), to be the target of your AJAX call, within your #detailView container so that the modal dialog created by JQuery won't be overwritten.

Lazarus
@Lazarus - the issue with that is i am originally loading the form dynamically so i populting #detailview upfront with the contents of "Detailcontent" View
ooo
I realise you are loading the form dynamically but I believe the problem is that when the dialog is showing you are then overwriting it with the dynamic data. You'd need to reinitialise the dialog once the dynamic data was loaded unless you either wrap #detailView in a DIV named, for example '#dialogwrapper', you'd then use `$("#dialogwrapper").dialog(...` or you use a different target inside #detailView for the AJAX response.
Lazarus
@Lazarus - makes sense. i definitely need a wrapper div here.
ooo