使用 MVC3、Razor、Jquery、Javascript。下面的代码循环显示一个包含字段和链接的表结构。每行上的链接都会触发一个 Jquery 模式对话框,该对话框将部分 View 页面显示为弹出窗口。但是弹出对话框仅适用于第一行......第二行及以下的链接将页面作为完整的网页打开,而不是弹出模式对话框。如何解决这个问题..感谢您的帮助。
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Category)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }, new { id = "modalEdit" }) |
</td>
</tr>
这是 Jquery 模式对话框代码。
<script type="text/javascript">
$(document).ready(function () {
//initialize the dialog
$("#resultEdit").dialog({ modal: true, width: 300, resizable: true, position: 'center', title: 'Edit Information', autoOpen: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
});
});
$(function () {
$('#modalEdit').click(function () {
//load the content from this.href, then turn it into a dialog.
$('#resultEdit').load(this.href).dialog('open');
return false;
});
});
最佳答案
这可能是因为您所有的编辑链接都具有相同的 id!
这将使 jquery 的行为变得非常不可预测!
改为给您的编辑链接一个共享类,如下所示:
@Html.ActionLink("Edit", "Edit", new { id = item.ID }, new { @class = "modalEdit" })
并将您的选择器更改为:
$('.modalEdit').click(function () {
关于javascript - MVC3 - 只有第一行链接适用于 Jquery 模态对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6333851/