I am working on ASP.NET MVC 3 application and I have a jquery dialogue with Ok button. On click of OK I want to submit a form using jquery AJAX.
My ajax call looks like this:
$("#free-trial").dialog({
autoOpen: false,
autoResize: true,
buttons: {
"OK": function () {
if (notvalid()) {
$(".ui-dialog-titlebar").hide();
$("#dialog-freetrial-insufficientdata").dialog({ dialogClass: 'transparent' });
$("#dialog-freetrial-insufficientdata").dialog("open");
}
else {
$('#frmCreateTrialAccount').live('submit', function (e) {
e.preventDefault();
$.ajax({
cache: false,
async: true,
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
success: function (data) {
alert(data);
}
});
});
jQuery(this).dialog('close');
}
}
},
open: function () {
$('.ui-dialog-buttonset').find('button:contains("OK")').focus();
$('.ui-dialog-buttonset').find('button:contains("OK")').addClass('customokbutton');
}
});
where as form looks like this:
@using (Html.BeginForm("CreateTrialAccount", "Home", FormMethod.Post,
new { Id = "frmCreateTrialAccount" } ))
{
}
and controller action looks like this:
[HttpPost]
public JsonResult CreateTrialAccount(FormCollection form) {
return Json("dummy data");
}
but form is not submitted on this method.
I have these files included in layout page:
<link href="@Url.Content("~/Content/css/smoothness/jquery-ui-1.10.0.custom.css")" rel="stylesheet" type="text/css" media="screen"/>
<script src="@Url.Content("~/Scripts/jquery-1.9.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.10.2.custom.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
Please suggest me solution to this.