如何在jquery对话框确认后隐藏行

时间:2012-08-22 08:43:01

标签: jquery asp.net-mvc jquery-ui

我在桌子上有一个@ Html.Actionlink(....)。我正在显示一个jquery对话框以进行确认。 一切正常。 但是我想在用户点击“继续”后隐藏该行,并且链接操作返回“true”。

我正在使用以下jquery代码。

var unapproveLinkObj;
    // delete Link
    $('.unapprove-link').click(function () {
        unapproveLinkObj = $(this);  //for future use
        $('#unapprove-dialog').dialog('open');
        return false; // prevents the default behaviour
    });

    $('#unapprove-dialog').dialog({
        autoOpen: false, width: 400, resizable: false, modal: true, 
        buttons: {
            "Continue": function () {
                $.post(unapproveLinkObj[0].href, function (data) {  //Post to action
                    if (data == '<%= Boolean.TrueString %>') {

                      // I want to hide the row here.....

                    }
                    else {
                        //Display Error
                    }
                });
                $(this).dialog("close");
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

有什么方法可以刷新页面,或者只是隐藏行而不刷新.. ??

编辑:这是Html

 @foreach (var i in Model)
{
    <tr class="grtr">
        <td>@i.CustomerName</td>
        <td>@i.BranchName
        <br />
        @i.Address
        </td>

        <td>@i.PostCode</td>
        <td>@i.City</td>
        <td>@i.Telephone</td>


            @if (!string.IsNullOrEmpty(i.Latitude))
            {
                <td>Yes</td>
            }
            else
            {
                <td>No</td>
            }
            @if (!string.IsNullOrEmpty(i.Longitude))
            {
                <td>Yes</td>
            }
            else
            {
                <td>No</td>
            }

        <td>@i.IsClaimed</td>
        <td>@Html.ActionLink("Approve", "Approve", "Location", new { id = @i.ID }, new 
       {
           @class="unapprove-link"

       })</td>
        <td>
        @Html.ActionLink("Delete", "Delete", "Location", new { id = @i.ID }, new {@class="delete-link"})

       </td>
        <td>Map</td>
    </tr>
}

3 个答案:

答案 0 :(得分:0)

据我了解,您的链接位于<td>内,并且您希望隐藏包含该td的行...并且您将锚点对象存储在unapproveLinkObj

所以,隐藏包含unapproveLinkObj对象的那一行。你可以尝试

unapproveLinkObj.parents('tr').hide();

或者如果要刷新页面,可以尝试

location.reload();

答案 1 :(得分:0)

如果用户点击continue时没有错误,请考虑以下情况:

if (data == '<%= Boolean.TrueString %>') {

       // I want to hide the row here.....
       $("table").hide(); // table is the id or class to access the table contents    

}

答案 2 :(得分:0)

if (data == '<%= Boolean.TrueString %>') {

       // I want to hide the row here.....
       $(".grtr").hide(); // access the row contents    

}