Passing a variable to an action in jQuery

I'm using MVC2 with jquery.

I'm trying to open a partial view in a jquery Dialog container, passing an itemID of an object to be deleted.

What I'm doing to accomplish this is passing in an action that renders a view to jquery, which I can get to work without variables. If I try to pass in the ID of the object to be deleted, the action doesn't even trigger. My likely foil is where I am passing in the variable.

Here's my jquery code:

    $(function () {
        var itemToDelete
            autoOpen: false,
            width: 400,
            resizable: false,
            title: 'Delete Item',
            modal: true,
            open: function(event, ui) {
                //This calls the action if I don't try to pass in the variable
                $(this).load("<%: Url.Action("Delete") %>",
                        item: itemToDelete 
                buttons: {
                "Close": function () {

        $('#item-delete-button').click(function () {
            itemToDelete = $(this).find("input").val()

Here's what pertinent part the view looks like.

<div id="item-delete-button" class="item-delete-button">
                        <%:Html.Hidden("item-delete-content", model.ItemID.ToString(), New With {.id = "item-delete-content", .class = "item-delete-content"})%>

If I click "Delete", the jquery happens and an empty dialog window opens. If I don't try to pass in the "itemToDelete" variable, then the action triggers fine, but of course, I'm not going to get far without knowing what item I want to delete.

So as I said, the issue is that I'm failing to pass in the right variable to my action. It's likely a simple mistake, and I'm relatively new to jquery.


Does it work if you replace:

$(this).load("<%: Url.Action("Delete") %>",
                    item: itemToDelete 

with this?

$(this).load('<%: Url.Action("Delete") %>?item=' + itemToDelete);

Need Your Help

Dragged item disappears after drop with ajax

jquery jquery-ui jquery-ui-draggable jquery-ui-droppable

I really have problems with the jQuery drag and drop. So let me explain the situation a bit.

Connect to BLE device and send/read data via NSNetService on iOS 7

ios iphone bluetooth nsnetservice nsnetservicebrowser

I have an iPhone app which communicates with external device via NSNetService.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.