我有一个jqGrid,其中我根据列显示动态列和行。
我的问题是关于应该显示的行,如果我在我的控制器类中写了一个内部类:
public class MeetingClass
{
public MeetingClass()
{
Data = new List<Dictionary<string, object>>();
}
public string records { get; set; }
public int total { get; set; }
public int Page { get; set; }
public int PageSize { get; set; }
public string SortColumn { get; set; }
[JsonExtensionData]
public List<Dictionary<string, object>> Data { get; set; }
}
在我的控制器中有以下内容:
var jsonData = new MeetingClass
{
records = "",
total = cbrUsers.Count,
Page = page,
PageSize = rows,
SortColumn = sidx
};
cbrUsers.ForEach(x =>
{
var item = new Dictionary<string, object>();
jsonData.Data.Add(item);
int counter = 1;
item.Add("Deltagare", x.FullName);
meeting.SecondOpinionGroup.OrderBy(y => y.SecondOpinionGroupId).ForEach(z =>
{
item.Add("Grupp" + counter, "false");
counter++;
});
item.Add("Ta_bort", "Ta bort deltagare");
});
return Json(jsonData, JsonRequestBehavior.AllowGet);
完美无缺。我尝试用不同的风格编写我的控制器并跳过内部类具有以下内容:
var jsonData = new
{
records = "",
total = cbrUsers.Count,
Page = page,
PageSize = rows,
SortColumn = sidx,
Data = new List<string>()
};
cbrUsers.ForEach(x =>
{
int counter = 1;
var item = new Dictionary<string, object>();
item.Add("Deltagare", x.FullName);
meeting.SecondOpinionGroup.OrderBy(y => y.SecondOpinionGroupId).ForEach(z =>
{
item.Add("Grupp" + counter, "false");
counter++;
});
item.Add("Ta_bort", "Ta bort deltagare");
jsonData.Data.Add(JsonConvert.SerializeObject(item));
});
我没有收到任何错误,但我的jqgrid在行中是空的,JsonConvert.SerializeObject
怎么办不行,但属性[JsonExtensionData]
有效?
最诚挚的问候Erik