// ajax代码 $.ajax({ type: "POST", url: "Controller/Action", data: { name: "John", age: 30 }, success: function (result) { alert("success"); }, error: function (xhr, status, error) { alert("error"); } });
// MVC控制器方法 [HttpPost] public ActionResult Action(string name, int age) { if (ModelState.IsValid) { //处理数据并返回结果 return Json(new { Success = true }); } else { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } }
上一篇:Ajax向MVC控制器发送了空值
下一篇:Ajax向php检索表单数据