jquery-modal icon indicating copy to clipboard operation
jquery-modal copied to clipboard

C# forms inside modal don't work as modal is moved from the DOM to another place and and not restored on close.

Open kornerson opened this issue 5 years ago • 1 comments

In C# Forms only variables inside the

are read when the form is sent by POST. Probably the same for some other programming framework.

If a form fields are placed in the modal once the modal is opened the modal is moved from it's original position in the DOM to another one, outside the <FORM>. Once the modal it's closed, it's not restored to the original position, so the values of the fields in the modal never reach the POST and are not read by the server code.

One way to solve this is that once the modal is closed, place it again in the original position in the DOM so the forms behave as expected.

To solve the problem in the time being in asp.net you can use this code that restores the modal inside the

in c#.

$('#modal').on($.modal.CLOSE, function (event, modal) { var element = $('#modal').detach(); $('#aspnetForm').append(element); });

kornerson avatar Sep 26 '19 07:09 kornerson

I have an another solution (basically the same) for each modal of you application :

$('.modal').on($.modal.AFTER_CLOSE, function(event, modal) {
    $(this).insertAfter($(modal.$anchor));
});

with this function, after the modal is closed (after animation for exemple), i replace the modal after the button action.

devcut avatar Nov 04 '20 13:11 devcut