I have got this simple form:
@using (Ajax.BeginForm(\"CreateProductFromAjaxForm\",\"Product\" ,
null,
new AjaxOptions() {
in page
new AjaxOptions() {
OnSuccess = "getresult",
}
in javascript
function getresult(data){
alert(data.x);
}
in c#
[HttpPost]
public ActionResult CreateProductFromAjaxForm(CreateProductModel model)
{
if (!ModelState.IsValid)
{
return Json("error", JsonRequestBehavior.AllowGet);
}
//add to database
return Json(model, JsonRequestBehavior.AllowGet);
}