[英]MVC Url.Action with glyphicon to call jquery dialog
我的页面上有以下剃须刀:
<a href="@Url.Action("CopyRequestData", "MyRequests", new { area = "Request", id = itm.RequestID })">
<span class="glyphicon glyphicon-copy OptionButton padding-10" id="btnCopyRequest" style="margin-left: 10px;" rowid="@itm.RequestID" data-toggle="popover" data-placement="left" data-content="Create a new request based on this one"></span>
</a>
我也有这个JQuery代码:
$('#dialog-Copy-request').dialog({
autoOpen: false, width: 800, resizable: false, modal: true,
title: "Request",
buttons: {
"Yes": function () {
//CopyRequest();
return true;
$(this).dialog("close");
},
"No": function () {
return false;
$(this).dialog("close");
}
}
});
$(document).on('click', '#btnCopyRequest', function () {
rowid = $(this).attr('rowid');
$('#dialog-Copy-request').dialog('open');
});
这样,单击图标按钮时将显示该对话框,但仅在加载新视图的时间内显示。
该对话框有两个按钮:是和否。
我希望仅在单击“是”时才加载新视图。
如何与图标按钮的href结合使用?
您可以尝试在单击时模糊href,然后在单击“是”时将位置设置为href。
编辑的html:
<a id="btnCopyRequest" href="@Url.Action("CopyRequestData", "MyRequests", new { area = "Request", id = 1 })">
<span class="glyphicon glyphicon-copy OptionButton padding-10" style="margin-left: 10px;" rowid="1" data-toggle="popover" data-placement="left" data-content="Create a new request based on this one"></span>
</a>
jQuery编辑
$('#dialog-Copy-request').dialog({
autoOpen: false, width: 800, resizable: false, modal: true,
title: "Request",
buttons: {
"Yes": function () {
window.location.href = $('#btnCopyRequest').attr('href');
$(this).dialog("close");
},
"No": function () {
return false;
$(this).dialog("close");
}
}
});
$(document).on('click', '#btnCopyRequest', function () {
event.preventDefault();
rowid = $(this).attr('rowid');
$('#dialog-Copy-request').dialog('open');
});
在mwwallace8的帮助下,我找到了解决方法。
$('#dialog-Copy-request').dialog({
autoOpen: false, width: 600, resizable: false, modal: true,
title: "Request",
buttons: {
"Yes": function () {
window.location.href = linkObj;
$(this).dialog("close");
},
"No": function () {
$(this).dialog("close");
}
}
});
$(document).on('click', '#btnCopyRequest', function () {
rowid = $(this).attr('rowid');
linkObj = $(this).context.parentNode.href;
$('#dialog-Copy-request').dialog('open');
return false;
});
诀窍是将href链接存储在全局变量中,并将“ return false”存储在其中。 在点击事件中。 然后将window.location.href设置为存储的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.