我有一个按钮,提示用户他的动作(删除smth)。如果用户确认,我想用ActionMethod
执行postback
。我怎样才能做到这一点?
答案 0 :(得分:2)
是的,这很简单,你可以这样做
<强> JS 强>
$('#id-of-your-button').click(function() {
if(confirm('Are you sure'))
document.location = '/controller/action/id_to_delete';
});
或使用回发
$('#id-of-your-button').click(function() {
if(!confirm('Are you sure'))
return false;
});
如果您的按钮不是提交按钮,则可以这样做
$('#id-of-your-button').click(function() {
if(confirm('Are you sure'))
$('#id-of-your-form').submit();
return false;
});
如果您没有任何内容(表单和提交按钮)
$('#id-of-your-button').click(function(){
$.ajax({ url: '/controller/action',
dataType: 'html',
data: { id_to_delete: $('#where_are_you_holding_your_value').val() },
type: 'post',
success: function(data) {
alert('your item is deleted');
}
});