【发布时间】:2014-12-04 18:01:40
【问题描述】:
我有以下代码:
public ActionResult AjaxHandler(jQueryDataTableParamModel param)
{
/* PROBLEM */
var allCompanies = DataRepository.GetCompanies();
/* PROBLEM */
var result = from c in allCompanies
select new[] { c.Name, c.Address, c.Town };
return Json(new { sEcho = param.sEcho,
iTotalRecords = allCompanies.Count(),
iTotalDisplayRecords = allCompanies.Count(),
aaData = result
},
JsonRequestBehavior.AllowGet);
}
我需要帮助写作
DataRepositry.GetCompanies();
标记为问题的部分可以帮助我编写一个函数,该函数返回适合使代码运行的数据。我知道它应该是某种 Json。但我不知道如何使它工作。
DataRepository.GetCompanies() <- could be any function, I just need to make it work
我试图这样做:
var allCompanies = new List<string[]>() {
new string[] {"1", "Microsoft", "Redmond", "USA"},
new string[] {"2", "Google", "Mountain View", "USA"},
new string[] {"3", "Gowi", "Pancevo", "Serbia"}
};
var newJson = JsonConvert.SerializeObject(allCompanies);
var allCompanies = newJson;
那没用。
解释:
这是一个更大的项目的一部分,基本上它假设填充 DataTable,我得到的确切错误。这是一个附加的屏幕。
【问题讨论】:
-
您尝试时遇到了什么错误?
-
解释“没用”???您是否遇到异常、HTTP 错误、客户端错误?
标签: asp.net asp.net-mvc json serialization