我使用的是mvc5,.net 4.5
我有两个变量,其中包含数据列表
两个变量中的数据分别从两个表中获取
当我调试变量data1时,它包含像
[0] = {value1 = "place1", money = 100}
[1] = {value2 = "place2", money = 200}
[2] = {value3 = "place3", money = 300}
然后我调试第二个变量data2,其中包含像
这样的数据[0] = {value2 = "product1", money = 100}
[1] = {value1 = "product2", money = 200}
[2] = {value1 = "product3", money = 300}
我想要一个数组中的变量,因为该操作是由ajax调用的。代码如下:
public JsonResult Process()
{
var data1 = fetch from table1;
var data2 = fetch from table2;
data[][] = .. i dont how to do this
--i want data like = data{data1, data2}
return Json(data);
}
提前致谢
答案 0 :(得分:1)
只需创建一个定义新数据类型的新类:
public class MyData
{
public List<Data1> Data1 {get;set;}
public List<Data2> Data2 {get;set;}
}
将其作为json返回:
public JsonResult Process()
{
var data = new MyData
{
Data1 = fetch from table1,
Data2 = fetch from table2
};
return Json(data);
}