//controller
public ActionResult AjaxTesting()
{
return View();//This method to redirect to view page
}
[HttpPost]//This method to received the
data form view.
public JsonResult AjaxTesting(AjaxTesting ajaxTesting)
{
return Json(ajaxTesting.customerName, JsonRequestBehavior.AllowGet);
}
//Views: Jquery
//To pass the data from
view to controller
$(document).ready(function () {
$("#SaveID").click(function () {
var
CustomerInfo = {
"CustomerName":$("#CustomerName").val(),
"MobileNumber":$("#MobileNumber").val()
}
$.ajax({
url: "AjaxTesting",
type: "POST",
contentType: "application/json;
charset=utf-8",
data: "{AjaxTesting:" +
JSON.stringify(CustomerInfo) + "}",
success: function(data)
{
alert("function Name:" + data);
}
})
});
});
No comments:
Post a Comment