简体   繁体   English

如何将JSON数据中的列表传递给MVC4中的View?

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

我需要使用Json从控制器将对象列表传递给View,用Java脚本的语法访问列表对象及其属性,然后将它们添加到数据表中?

In Controller You need use anonymous object to return json data 在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)

In function javascript 在功能的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