ajax 请求JSON在MVC使用注意事项:
ajax前台请求方式:
MVC后台返回方法:
第一种:对象转换成JSON格式再通过Response.Write(json);写入到文件流中:
string json = JsonConvert.SerializeObject(new { BetEniqures = rsp1.BetEniqures, AboveGameDrawDates = rsp1.AboveGameDrawDates, EventType = eventType });
Response.Write(json);
Response.End();
第二种:直接使用JSON格式直接转送:
public ActionResult JsonResult()
{
//自动将传入的对象序列化成json格式写入到response对象中
return Json(new { Name = " 八戒", Age = 500 }, JsonRequestBehavior.AllowGet);
}
浙公网安备 33010602011771号