为什么我的ajax调用需要这么长时间

本文关键字:长时间 我的 ajax 调用 为什么 | 更新日期: 2023-09-27 18:07:29

当我进行AJAX调用以接收在此c#代码中定义的json对象时,我必须46秒以上才能接收该对象。对象本身只有12kb大。是因为我的c#代码(执行时间不长?)还是其他原因?我正在我的本地IIS服务器上测试它。

这是我的代码:

[AcceptVerbs(HttpVerbs.Post)]
    public JsonResult LoadAudit(int id, string sheet)
    {
        FactsCustomerRepository<Cateringaudit> repo = new FactsCustomerRepository<Cateringaudit>();
        //IQueryable<Cateringaudit> result = repo.GetAll(i => i.State == 1);
        Cateringaudit result1 = repo.Get(id);
        WorkBook wb = new WorkBook();
        wb.read(new MemoryStream(result1.ExcelData));
        object[] jsonObjects = new object[3];
        //sheetnames to collect data from
        string[] sheetNames = { "contract", "proces", "output" };
        //itterate trough all sheets in excel file
        for (int sheetCount = 0; sheetCount < sheetNames.Length; sheetCount++)
        {
            wb.Sheet = wb.findSheetByName(sheetNames[sheetCount]);
            //Create new array with same lenght as rows with data
            Dictionary<string, string[]> excelData = new Dictionary<string, string[]>();
            //iterate trough all rows in worksheet
            for (int i = 1; i < wb.LastRow + 2; i++)
            {
                excelData.Add(blabla);
                jsonObjects[sheetCount] = excelData;
            }
        }
        return Json(jsonObjects);
    }

为什么我的ajax调用需要这么长时间

用c#打开excel表格的速度慢得离谱。有很多很棒的库,它们的速度更快:

EEPLUS: http://epplus.codeplex.com/

但是首先要排除Excel:您是否尝试返回静态JsonObject而不使用Excel ?

[AcceptVerbs(HttpVerbs.Post)]
public JsonResult LoadAudit(int id, string sheet)
{
    return Json(); // something like this
}