I have a button that prompts user about his action(deleting smth). If user confirms, I want to execute ActionMethod with postback. How can i achieve that?
-
2See stackoverflow.com/questions/764965/… and stackoverflow.com/questions/1843017/…Daveo– Daveo2011-10-14 13:33:20 +00:00Commented Oct 14, 2011 at 13:33
Add a comment
|
1 Answer
Yes that is simple, you can do it this way
JS
$('#id-of-your-button').click(function() {
if(confirm('Are you sure'))
document.location = '/controller/action/id_to_delete';
});
or with the postback
$('#id-of-your-button').click(function() {
if(!confirm('Are you sure'))
return false;
});
if your button is not submit button than you can do it this way
$('#id-of-your-button').click(function() {
if(confirm('Are you sure'))
$('#id-of-your-form').submit();
return false;
});
if you don't have anything (form and submit button)
$('#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');
}
});
3 Comments
Ilya Smagin
What if it is post method(and it obviously has to be be) ?
Senad Meškin
I have fixed code, look at it now, if your button is submit button of your form
Ilya Smagin
What if i don't have submit button?