InspiredBy
InspiredBy

Reputation: 4320

How to pass parameters to an action that's called on JQuery dialog() Open event

Good morning.

I have a modal JQuery dialog that on Open calls and loads a Partial View. Good example can be seen here https://stackoverflow.com/a/4802423/1193841 but I'll re-paste:

<script type="text/javascript">
$(function () {
    $('#dialog').dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        title: 'hi there',
        modal: true,
        open: function(event, ui) {
            //Load the CreateAlbumPartial action which will return 
            // the partial view _CreateAlbumPartial
            $(this).load("@Url.Action("CreateAlbumPartial")");
        },
        buttons: {
            "Close": function () {
                $(this).dialog("close");
            }
        }
    });

    $('#my-button').click(function () {
        $('#dialog').dialog('open');
    });
});

In my case ActionMethod "CreateAlbumPartial" takes an ID parameter that's passed from another page with onclick="" event.

How can I make that Id available to pass to an ActionMethod when its called as shown above ? Something like

$('#dialog').dialog('open',Id)

Would be awesome but I dont think that's how it works.

P.S. Right now I'm displaying my popup by doing $.post() to load .html(data) to div and then displaying that DIV in a .show().dialog('open'). However, instead of having my Action method call and Dialog related stuff separately I would really like to re-do it the way I'm asking to keep all logic in one place.

Thank you in advance.

Upvotes: 2

Views: 1188

Answers (1)

user1284460
user1284460

Reputation: 128

Why dont you make a hidden control and assign the value to that and use it in the dialog

Upvotes: 1

Related Questions