簡體   English   中英

如何將JSON數據中的列表傳遞給MVC4中的View?

[英]How pass a list in JSON Data to View in MVC4?

我需要使用Json從控制器將對象列表傳遞給View,用Java腳本的語法訪問列表對象及其屬性,然后將它們添加到數據表中?

在Controller中,您需要使用匿名對象來返回json數據

var result = // object which contain result
var jsonData = result.select(x=>new{
   PropertyA = x.A,
   PropertyB = x.B,
   PropertyC = x.C,
});

return Json(jsonData, JsonRequestBehavior.AllowGet)

在功能的JavaScript

success:function(data){
 $.each(data,function(i,data){
    //loop and insert your table
    data.PropertyA //get data  
})
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM