Web MVC编程:The length of the string exceeds the value set on the maxJsonLength propert


返回从后台JSON到前台的时候蹦出的错:
The length of the string exceeds the value set on the maxJsonLength propert

网上的解决办法都是说在web.config里加段:
 
    
      
        
      
    
  

但是没起作用
我的解决办法是:
public ActionResult Get(DateTime dateFrom, DateTime dateTo)
		{
			DataTable list = GetList(dateFrom, dateTo);
			var salegoodsList = list.AsEnumerable().GroupBy(t => t["Dimension0"]).Select(n =>
				new
				{
					goodsid = n.Key,
					qty = n.Sum(s => s["销售数量"] == "" ? 0 : Convert.ToInt32(s["销售数量"])),
					stock = n.Sum(s => s["库存"] == "" ? 0 : Convert.ToInt32(s["库存"]))
				});

                       //关键代码,可设置JSON的长度
			System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
			serializer.MaxJsonLength = Int32.MaxValue;

			var retobject = new
			{  salegoodsList = salegoodsList ,
                           dateFrom = dateFrom 
                        }; 
var result = new ContentResult(); 
result.Content = serializer.Serialize(retobject); 
result.ContentType = "application/json"; 
return result;
}



你可能感兴趣的:(C#,html,input标签,C#,ASP.NET)