无法加载服务器响应的资源状态为500(内部服务器错误)

时间:2014-10-02 08:14:07

标签: jquery asp.net-mvc

我有一个ajax电话:

$.ajax({
         url: '@Url.Action("LoadCategory", "Home")',
         type: 'GET',
         contentType: "application/json; charset=utf-8",
         data: { fstValue: modelDDLValue },
         success: function (result) {
           // do something here
        });

和Home Controller中的操作方法:

public JsonResult LoadCategory(string fstValue)
 {
      int modelId = 0;
        if (fstValue != "")
            modelId = Convert.ToInt32(fstValue);

        var result = unitOfWork.CategoryRepository.GetCategoriesForModel(modelId);

        string listUL = "<ul class=\"root\">";

        IList<SelectListItem> Data = new List<SelectListItem>();
        foreach (Category cat in result)
        {
            listUL += "<li><a class='parent' href=\"javascript:void()\">" + cat.CategoryNameEng + "<span class=\"value\">" + cat.Id.ToString() + "</span></a>";
            Data.Add(new SelectListItem()
            {
                Text = cat.CategoryNameEng,
                Value = cat.Id.ToString(),
            });

            if (cat.SubCategories.Count() > 0)
            {
                listUL += "<ul class=\"l1\">";
                foreach (SubCategory scat in cat.SubCategories.Where(s => s.ModelId == modelId).ToList())
                {
                    listUL += "<li><a class='sub' href=\"javascript:void()\">" + scat.SubCategoryNameEng + "<span class=\"value\">" + "S" + scat.Id.ToString() + "</span></a></li>";
                    Data.Add(new SelectListItem()
                    {
                        Text = scat.SubCategoryNameEng,
                        Value = "S" + scat.Id.ToString(),
                    });
                }
                listUL += "</ul>";
            }
            listUL += "</li>";
        }
        listUL += "</ul>";

        // add listUL into Data as the last element
        Data.Add(new SelectListItem() { Value = "listUL", Text = listUL });

     return Json(Data, JsonRequestBehavior.AllowGet); 
 }

但是在webhost上我总是收到错误“无法加载资源服务器响应状态为500(内部服务器错误)”。

我尝试用$ .get()和其他东西替换ajax方法,在stackoverflow中阅读关于这个主题的所有答案,但没有运气。

我该如何处理?非常感谢提前!

1 个答案:

答案 0 :(得分:0)

问题在于此错误: 已经有一个与此命令关联的开放DataReader必须先关闭

解决方案在这里找到: There is already an open DataReader associated with this Command which must be closed first

添加连接字符串 MultipleActiveResultSets = true 解决了这个问题。