@{
ViewBag.Title = "Index";
}
<html>
<body>
<input type="button" value="提交" id="sumit" />
</body>
<script src="~/Scripts/jquery-1.7.1.js"></script>
</html>
<script type="text/javascript">
$(function () {
$("#sumit").click(function () {
var postdata = [];
postdata.push({ Name: "小强", Sex: true, Age: 36, No: 795245 });
postdata.push({ Name: "小明", Sex: true, Age: 5, No: 89898 });
postdata.push({ Name: "小强", Sex: true, Age: 18, No: 13884 });
var datas = JSON.stringify(postdata);
$.ajax({
type: "POST",
data: "data=" + datas,
url: "/RequestForm/SumitFrom ",
success: function (serverResult) {
}
})
})
})
</script>
1 using Newtonsoft.Json;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Web;
6 using System.Web.Mvc;
7
8 namespace 学习功能.Controllers
9 {
10 public class RequestFormController : Controller
11 {
12 //
13 // GET: /RequestForm/
14
15 public ActionResult Index()
16 {
17 return View();
18 }
19
20 public JsonResult SumitFrom()
21 {
22 string dataStr = Request.Form["data"];
23 //获取传过来的参数
24 if (!string.IsNullOrWhiteSpace(dataStr))
25 { //把字符串利用 JsonConvert.DeserializeObject方法转换成对象
26 List<Person> formdatas = JsonConvert.DeserializeObject<List<Person>>(dataStr);
27
28 }
29 return Json(new { },JsonRequestBehavior.AllowGet);
30 }
31 }
32
33 public class Person
34 {
35 public string Name { get; set; }
36 public bool Sex { get; set; }
37 public int Age { get; set; }
38 public int No { get; set; }
39
40
41 }