我正在做本教程。
在我的控制器类中,我有我的
public JsonResult GetAllUser(){
List<database1> allUser = new List<database1>();
using (dbContext1 dc = new dbContext1 ())
{
allUser = dc.database1.ToList();
}
return new JsonResult()
{
Data = allUser,
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
MaxJsonLength = Int32.MaxValue
};
}
public JsonResult GetUserWithSerialNumber(string prefix){
List<database1> allUser = new List<database1>();
using (dbContext1 dc = new dbContext1())
{
allUser = dc.database1.Where(a => a.SerialNumber.Equals(prefix)).ToList();
}
return new JsonResult { Data = allUser, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
截至目前,GetAllUser(( 不起作用,而 get GetUserWithSerialNumber(( 返回它应该返回的内容。最初 GetAllUser(( 工作,然后它给了我
"The length of the string exceeds the value set on the maxJsonLength property."
所以我把"Int32.MaxValue"放在 GetAllUser 方法中,现在当我运行网页并单击 GetAllUser 按钮时,它给了我
A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.Script: http://localhost:54936/Scripts/jquery-1.10.2.js:7017
我所有其他方法都可以工作,除了 GetAllUser((。我的 cshtml 和其他代码看起来与教程中的 on 完全一样,所以我不确定我做错了什么。
我发现我收到脚本消息的唯一原因是因为我的数据库很大。遍历所有条目、将它们放入列表中并将其作为对象放置的时间太长。