0
我在創建視圖上創建了一個模態。我有三個按鈕 - '添加條件','無條件',和'取消'。當點擊每個按鈕時,我希望它執行一個操作。到目前爲止,唯一可用的按鈕是'取消'按鈕,因爲我使用的是data-dismiss="modal"
而不是我的控制器中的代碼。我的問題是你如何在控制器中訪問ActionResult
。我已經嘗試了以下Modal代碼和相應的Ajax代碼。模式功能按鈕Onclick
模態:
<button type="button" id="confirmItem" data-target="#confirmModal" data-toggle="modal" @*data-id="#AddConditions">Create</button>
<body>
<br/>
<div class="modal fade" id="confirmModal" tabindex="-1" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dissmiss="modal" aria-hidden="true">@*×*@</button>
<h4 class="modal-title">Confirm</h4>
</div>
<div class="modal-body">
<p>Confirm that Requested Burn Conditions should be added.</p>
</div>
<div class="modal-footer">
<button id="btnAddConditions" type="button" class="btn btn-primary">Add Conditions</button>
<button id="btnNoConditions" type="button" class="btn btn-primary" >No Conditions</button>
<button data-dismiss="modal" type="button" class="btn btn-default">Cancel</button>
</div>
</div>
</div>
</div>
</body>
阿賈克斯:
<script type="text/javascript">
var checkConditon;
$(document).ready(function(){
$(".confirmItem").click(function (e) {
checkConditon = $(this).data('id');
alert("confirm item " + $(this).data('id'));
});
$('#btnAddConditions').click(function() {
alert("add condition " + $(this).data('id'));
window.location = "/RequestedBurns/AddCondition/" + checkConditon;
});
$('#btnNoConditions').click(function() {
$.ajax({
type: "POST",
url: "Create",
success: function(){
alert("success")
},
error: function (error) {
alert("Error Ajax not working: " + error);
}
});
});
});
</script>