i have the following ajax.actionlink:-
@Ajax.ActionLink("Delete", "Delete", "Answer",
new { id = answer.AnswersID },
new AjaxOptions
{
OnBegin = "deleteconfirmation1",
HttpMethod = "Post",
UpdateTargetId = @answer.AnswersID.ToString(),
OnSuccess = "deleteconfirmation",
})
and the following deleteconfirmation1.js that should display a confirmation message before executing the ajax call:-
function deleteconfirmation1() {
jConfirm('Deletion Confirmation', 'Are you sure you want to delete this Answer');
}
the problem that i am facing is that the onbegin confiramtion will not prevent the onsuccess script from being executed even if the user click on the cancel button? so how i can make the OnBegin to work as a confirmation stage, so the application will wait for the user selection either “Ok” or “cancel” before processding with the ajax call or not !!! ??
BR
You need return
falsefrom theOnBeginmethod to cancel the request.Note that
Ajax.ActionLinkalready supports confirmation with the AjaxOptions.Confirm property.You also need to include
~/Scripts/jquery.unobtrusive-ajax.jsin your view/layout to use the@Ajax.helpers.EDIT issue with jConfirm:
Your problem is that the signature of
jConfirmis the following:It’s instead of returning true/false expects a callback function which is called when the user clicked on ok/cancel.
This causes the problem because you need to return
falsefrom theOnBeginbut you don’t have a return value fromjConfirmjust in the callback…So you should wait for the callback…. see this SO question Can you wait for javascript callback?
(which is also about
jConfirm) for more information.The conclusion is that you cannot use
jConfirmto cancel the request with theOnBeginmethod.