When user clicks on a hyperlink , I want to run a background process. Before I run that I want to ask user's permission using jQuery dialogbox (form). When user clicks "ok" on the form , I want to run the action using jQuery ajax. If process fails then I want to update that popup with "Error". How do I do this in asp.net MVC using jQuery AJAX. Below is the code I tried
Here is my MVC Ajax begin form code
@using (Ajax.BeginForm("Action1", "Controller1", new AjaxOptions { UpdateTargetId = "eProcess" }, new { id = "eProcess" }))
{
@Html.Hidden("eID", eId);
@Html.Hidden("processName", "processName");
<div class="hide" id="dialog" title="Confirmation Required">
Are you sure you want to update this record? <br />
<input type="button" value="Hit" id="btnHit" />
</div>
}
and below is my dialog code
$("#dialog").dialog
({
dialogClass: "ee-detail-info",
closeOnEscape: false,
height: 200,
width: 300,
modal: true,
autoOpen: false,
open: function (event, ui) {
$("#btnHit").click(function () {
$('#processName')[0].value = processName;
document.forms.eProcess.submit();
});
}
});
I even tried using the .ajax method but still its doing full post back. I double checked my jQuery files. They are linked correctly on the page.
$("#eProcess")[0].submit(function () {
$.ajax({
url: $("#eProcess")[0].action,
success: function (res) {
alert("Success");
}
});
});
Update
I got it working with your solution. I had bug in my code.