I am trying to send a FormCollection
to an action in my controller but the action is never being hit.
Form:
<form class="form-horizontal" role="form" id="TestForm" onsubmit="return false">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input type="text" name="Blah1" />
<input type="text" name="Blah2" />
</div>
<input id="SubmitButton" type="submit" value="Submit" />
</div>
</div>
jQuery/Ajax:
$(document).ready(function () {
$("#SubmitButton").click(function () {
var form = $("#TestForm").serialize();
$.ajax({
url: "/Calculator/Post",
type: "POST",
data: form,
dataType: 'json',
success: function () {
alert("Success");
},
error: function () {
alert("Error");
}
});
});
});
Controller Action:
[HttpPost]
public JsonResult Post(FormCollection form)
{
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
The only thing that happens is the browser alerts the error message. Am I missing something that is causing the action to never be hit?