2

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.

Community
  • 1
  • 1
InspiredBy
  • 4,271
  • 6
  • 40
  • 67

1 Answers1

1

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

user1284460
  • 128
  • 1
  • 3
  • 14
  • Hmmmm +1...not a bad way around it I guess. I'd like to see if there is a better way, to pass in a parameter variable though. – InspiredBy May 17 '12 at 17:46
  • or send parameter in the url like this /controller/action/id and your actionresult will be ActionResult CreateAlbumPartial(int id). – user1284460 May 17 '12 at 18:00