jQuery对话框在浏览器中跳转到整页

时间:2015-05-19 14:52:00

标签: javascript jquery dialog

我有一个WebGrid对话框,显示项目列表:

 @if (Model.ItemsByLocation != null)
{
    @grid.GetHtml(
    tableStyle: "table",
    fillEmptyRows: true,
    headerStyle: "header",
    footerStyle: "footer",
    mode: WebGridPagerModes.All,
    firstText: "<<First",
    previousText: "<Prev",
    nextText: "Next>",
    lastText: "Last>>",
    htmlAttributes: new { id = "grid"},
    columns: new []
    {
        //grid.Column("ItemNumber", "Item"),
        grid.Column(header: "Item Number", format: (item) => Html.ActionLink((string)item.ItemNumber, "ShowItem", "Inventory", new { id = item.ItemNumber.ToString()}, new {onclick = "GetItemDetails(" + item.ItemNumber.ToString() + ");"})),
        grid.Column("ItemDescription","Desc"),
        grid.Column("ItemSerialNumber","SN"),
        grid.Column("itemLocationSite","Site"),
        grid.Column("ItemLocationBuilding","Bldg"),
        grid.Column("ItemLocationFloor","Flr"),
        grid.Column("ItemLocationOffice","Off"),
        grid.Column("ItemTypeDescription","Type"),
        grid.Column("FirstName","First"),
        grid.Column("LastName","Last")

    }) 

}
else {
 <p><i>No item to display</i></p>   
}

这是另一个页面的对话框 - 没问题。当我点击链接时,调用JS函数:

 function GetItemDetails(id) {
    var test = id;
    $.ajax({
        type: 'GET',
        url: '@Url.Action("ShowItem")?id=' + id,
        success: function (data) {
            $("#divDetails").html(data);
            $("#divDetails").dialog("open");
            $("#divDetails").show();
        }
    });
    return false;
}

这会在第一个对话框的顶部响应另一个对话框,但只有一两秒,然后两个对话框关闭,第二个对话框中的数据在浏览器中显示为整页。任何想法为什么会这样?

这是详细信息的对话框:

 $(document).ready(function () {
    //debugger;

    $("#divDetails").dialog({
        autoOpen: false,
        width: 'auto',
        resizable: true,
        title: 'Item Details',
        modal: true,
        closeOnEscape: false,
        show: {
            effect: 'drop', direction: 'up'
        },
        buttons: {
            "OK": function () {

                $(this).dialog("close");
            }
        }
    }).prev("ui-dialog-titlebar").css("background", "#FF3300");
    $(".dialog").click(function () {
        $("#divDetails").dialog("open");
    });

});

<div id="divDetails" style="display:none" class="ui-dialog-titlebar ui-widget-header">

 </div>

我在代码中放了一些断点,在显示第二个对话框后,调用控制器索引函数。这是怎么发生的?如果我从链接中删除ShowItem,它会这样做但是如果我把它放回去,它会调用ShowItem函数两次。为什么呢?

1 个答案:

答案 0 :(得分:0)

我仍然不知道问题是什么,但如果我将webgrid列更改为此,它可以正常工作:

 grid.Column(header: "Item Number", format:@<a href="#" onclick="GetItemDetails(@item.ItemNumber.ToString());return false;">@item.ItemNumber.ToString()</a>),