建立模型
public class Person{ public string Name { get; set; } public string Address { get; set; } public string Phone { get; set; }}
像下面的控制器
public ActionResult PersonTest() { return View(); } [HttpPost] public ActionResult PersonSubmit(Vh.Web.Models.Person person) { System.Threading.Thread.Sleep(2000); return Json(new {msg="Successfully added "+person.Name }); }
Java脚本
<script type="text/javascript"> function send() { var person = { name: $("#id-name").val(), address:$("#id-address").val(), phone:$("#id-phone").val() } $('#target').html('sending..'); $.ajax({ url: '/test/PersonSubmit', type: 'post', dataType: 'json', contentType: 'application/json', success: function (data) { $('#target').html(data.msg); }, data: JSON.stringify(person) }); }</script>