我有一个如下的代码块:
@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')"
因为有一个foreach语句,所以我不能使用像id这样的变量来使用e.preventDefault。
我在按钮点击事件上解决了这个问题,它很好地工作:
<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事件作为html属性放置,但它不起作用。
我需要做的是将我的参数传递给控制器并在“屏幕中央的网站”上打开新的_blank窗口。我已经满足了所有需求,除了最后一个。
我该如何解决这个问题?