gpt4 book ai didi

javascript - 如何在 ASP.NET MVC 4 中通过 Html.Actionlink 触发 window.open

转载 作者:行者123 更新时间:2023-11-29 15:30:35 25 4
gpt4 key购买 nike

我有一个代码块如下:

@foreach (System.Data.DataRow drEquipment in Model.EquipmentList.Rows)
{
<tr>
<td valign="top">@drEquipment["ColumnName"]<br /></td>
<td valign="top">@drEquipment["ColumnName"] - @drEquipment["ColumnName"]<br /></td>
<td valign="top">@drEquipment["ColumnName"]</td>
<td valign="top">@drEquipment["ColumnName"] - @drEquipment["ColumnName"]</td>
<td>@Html.ActionLink("Güncelle", "UpdateAction", new { SerialNumber = drEquipment["ColumnName"], StockSpecCd = drEquipment["ColumnName"], ResourceSpecTypeCd = drEquipment["ColumnName"] }, new { popup="{\"height\":250, \"width\":350}" })</td>
</tr>
}
@Html.ActionLink("Update", "UpdateAction", new { SerialNumber = drEquipment["ColumnName"], StockSpecCd = drEquipment["ColumnName"], ResourceSpecTypeCd = drEquipment["ColumnName"], new { popup="{\"height\":250, \"width\":350}" })

它像这样运行良好,但我无法在屏幕中心设置弹出窗口。这就是为什么我有一个如下的 onclick 事件:

onclick="MyPopup('/Account/UpdateAction', '350', '250')"

所以我不能使用像 id 这样的变量来使用 e.preventDefault,因为有一个 foreach 语句。

我在按钮点击事件上解决了这个问题,效果很好:

<button onclick="MyPopup('/Account/UpdateAction', '350', '250')">Update</button>

function MyPopup(url, width, height) {
var leftPosition, topPosition;
//Allow for borders.
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
//Allow for title and status bars.
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
//Open the window.
window.open(url, "_blank",
"status=no,height=" + height + ",width=" + width + ",resizable=yes,left="
+ leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY="
+ topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");

但是我无法将我的函数与 Html.Actionlink 一起使用。我将一个 onclick 事件作为 htmlAttritube,但它没有用。

我真正需要的是将我的参数传递给 Controller ​​并打开新的_blank 窗口“屏幕的站点中心”。我有我所有的需求,没有最后一个。

我该如何解决这个问题?

最佳答案

我以不同的方式做了我想做的事:

 @{
long WarehouseId = string.IsNullOrWhiteSpace(drEquipment["WAREHOUSE_ID"].ToString()) ? 0 : Convert.ToInt64(drEquipment["WAREHOUSE_ID"]);
string link = "/Account/EquipmentEdit?SerialNumber=" + drEquipment["SERIAL_NUMBER"] + "&StockCode=" + drEquipment["STOCK_CODE"] + "&WarehouseId=" + WarehouseId + "&WarehouseTypeCode=" + drEquipment["WAREHOUSE_TYPE_CODE"].ToString() + "&WhsStatusType=" + drEquipment["WHS_STATUS_TYPE"].ToString();
}

<td><a href="#" onclick="MyPopup('@link', '350', '250');">Update</a></td>

function MyPopup(url, width, height) {
var leftPosition, topPosition;
//Allow for borders.
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
//Allow for title and status bars.
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
//Open the window.
window.open(url, "_blank",
"status=no,height=" + height + ",width=" + width + ",resizable=yes,left="
+ leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY="
+ topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}

如果有办法处理 Html.ActionLink,我很想知道。我不想在我的 cshtml 页面中看到像“a href”这样的属性。

关于javascript - 如何在 ASP.NET MVC 4 中通过 Html.Actionlink 触发 window.open,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35325285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com