2016-12-05 47 views
0
List<string> _columns = new List<string>() { "Kurator", "Filial", "Klient", "Saldo", "Docs", "no_Docs", "Change", "Status" }; 
var columns = cols.Select(p => new { 
        data = p.ColumnName }); 

提斯給我對象JsonResult的數組:數據:Kurator,數據:孝等Lambda表達式到JSON陣列

這裏是數據=常數。我怎樣才能從另一個列表動態地使用它?

所以我需要從對象的兩個列表數據

List<string> list1 = new List<string>() { "lst1-1", "lst1-2", "lst1-3" }; 
List<string> list2 = new List<string>() { "lst2-1", "lst2-2", "lst2-3" }; 

var columns = cols.Select(p => new { 
         lst1-1= lst2-1 }); 

要得到的回報Json(columns, JsonRequestBehavior.AllowGet);

列=(lst1-1的數組:lst2-1,lst1-2:lst2- 1,lst1-3:lst2-1)

我已經打破了我的頭!

回答

0

嘗試:

var columns = from l1 in list1.Select((val, index) => new { val, index }) 
        from l2 in list2.Select((val, index) => new { val, index }) 
        where l1.index == l2.index 
        select l1.val + " : " + l2.val; 
+0

它返回 「LST1:LST2」 作爲字符串,但輸入工作看起來像{數據= 「Kurator」}其陣列的對象 –