我從@Html.ActionLink
調用jQuery對話框但是我很困惑要將動作參數傳遞給jQuery對話框。如何將它們CommunicationLocation
和CommunicationType
傳遞給jQuery對話框?如何在jQuery對話框中獲取ActionLink參數
@Html.ActionLink("Delete", "DeleteEmail", null, new { CommunicationLocation
= commemail.CommunicationLocation, CommunicationType = "email" },
new { @class = "modalDialog btn btn-success" })
對話框股利
<div id="dialog-confirm" title="Delete the item?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This item will be deleted. Are you sure?</p>
</div>
JS
<script type="text/javascript">
$(document).ready(function() {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true,
resizable: false,
height: 180,
});
$('.modalDialog').click(function() {
$("#dialog-confirm").dialog({
buttons: {
"Confirm": function() {
$.ajax({
url: 'customer/DeleteEmail',
type: 'Post',
data: //Need to pass parameters here,
success: function (result) {
$('#DivEmailContainer').html(result);
}
});
$(this).dialog('close');
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog("open");
return false;
});
</script>
控制器
[HttpPost]
public PartialViewResult DeleteEmail(string CommunicationLocation, string CommunicationType)
{
//Code here
}
對於另一種方法,我都會有每一行都有值,這樣我就可以在變量不存儲值,因爲我不不知道我點擊了哪一行 – James123
@ James123我已經更新了我的答案,以包括我在許多場合使用過的類似場景的解決方案。基本上,我創建了一些帶有一些查找ID的項目數組,如來自數據庫或索引的ID。當行被創建時,ID值被添加到'data-'屬性並且Javascript數組被更新爲新項目。在JS事件動作中,檢索id以獲取正確的數組項。 – jwatts1980