Find the parent form of a button inside a List
<p>I have a list of devices with each row containing a delete button. On clicking the delete button, i need to popup a dialog to get the reason for delete and then on OK, submit the parent form with deivce Id. The cshtml looks like</p>

<pre><code>foreach(var device in (Collection&lt;Device&gt;)ViewBag.Devices)
{
&lt;tr&gt;
&lt;td&gt; device.Name &lt;/td&gt;
&lt;td&gt; device.Description &lt;/td&gt;
&lt;td&gt;
    @using (Html.BeginForm("delete", "Devices", new {id="delete-device-form"}))
                      {
                          &lt;input type="hidden" name="deviceId" id="deviceId" value="@device.Id" /&gt;
                          &lt;input type="hidden" name="selectedAssignStatus" id="selectedAssignStatus" value="" /&gt;
                          &lt;input type="hidden" name="selectedreason" id="selectedreason" value="" /&gt;
                          @Html.HttpMethodOverride(HttpVerbs.Delete)
                          &lt;button type="button" name ="btnDelete" id="btnDelete" value="@device.Id" class="unassign"&gt; Delete&lt;/button&gt;

                          &lt;div id="dialog-message" title="Provide a Reason for Unassignment" class="hide"&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;span&gt;
                                          @Html.DropDownList("DeviceAssignmentStatuses", null, string.Empty, new {style = "width: 250px;"})
                                          @Html.Label("Device Assignment Status")
                                      &lt;/span&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;span&gt;  
                                          &lt;label&gt;
                                              Select a reason for unassignment&lt;/label&gt;
                                      &lt;/span&gt;
                                      &lt;span&gt;
                                          &lt;textarea id="reason" cols="30" rows="3"&gt;&lt;/textarea&gt;
                                      &lt;/span&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;   
                          &lt;/div&gt;
                      }
&lt;/td&gt;
&lt;/tr&gt;
}
</code></pre>

<p>My jquery looks like this</p>

<pre><code>$(".unassign").button().click(function () {
    $("#dialog-message").dialog({
        modal: true,
        width: 350,
        buttons: {
            OK: function () {
                alert($(this).val());
                var $form = $(this).closest("form"); //not working
                $form.submit();
                $(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });
});
</code></pre>

<p>I need help finding the correct parent for of the button in the OK: function() ,so that i can get the correct hidden fld value for deviceId on submit. Any help appreciated. Thanks,</p>
