【问题标题】:pass json data to JQGrid将 json 数据传递给 JQGrid
【发布时间】:2013-12-27 12:14:57
【问题描述】:

大家好,我是 mvc 的新手。我想在单独的行中显示每个组名,组名是从活动目录中检索的。这些组名需要显示到 jqgrid 中。我的代码能够在一行中显示所有组名,但不能在多行中显示 id。并且还选择了要移动到另一个 jagrid 中的项目。
这是我的模型类

public class AdGroups
{
    public int id { get; set; }
    public List< string> GroupName { get; set; }      
}

在下面的“list ls”中,可以获取 ls 中的所有域组。
这是我的操作方法,这里我的控制器名称是 JqgridController。

public JsonResult DomainNames()
{
    AdGroups adg = new AdGroups();
    List<AdGroups> li = new List<AdGroups>();
    List<string> ls = new List<string>();
    ls = GetADGroups("xyz.com");         
   var jsonData = new
    {
        rows = (
          from ct in li
          select new
          {
             id = ct.GroupName
           }).ToArray()
    };
    return Json(jsonData , JsonRequestBehavior.AllowGet);
}

我的看法是这样的

<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - Domain Names</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Scripts.Render("~/bundles/modernizr")
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="~/Scripts/jquery.jqGrid.src.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
</head>
<script type="text/javascript">
jQuery(document).ready(function () {
$("#list1").jqGrid({
url: '@Url.Action("DomainNames", "JQGrid")',
datatype: 'json',
rowNum: 5,
rowList: [10, 20, 30],
sortname: 'GroupName',
sortorder: 'desc',
viewrecords: true,
mtype: 'GET',
colNames: ['GroupName'],
colModel: [
{ name: 'GroupName', index: 'GroupName', align: 'left', sortable: false }
]
});
});
</script>
<div>
<table>
<tr>
<td>
<table id="list1"></table>
<div id="pager1"></div>
</td>           
</tr>
</table>
</div>

【问题讨论】:

    标签: json asp.net-mvc-4 jqgrid


    【解决方案1】:

    模型应该是这样的:

    public class AdGroups
    {
         public int id { get; set; }
         public List<string> GroupName { get; set; }  
         public string DomainGroup {get;set;}    
    }
    

    动作方法应该是这样的:

    List<AdGroups> li = new List<AdGroups>();
    List<string> ls = new List<string>();
    ls = GetADGroups("xyz.com");
    for (int i = 0; i < ls.Count; i++)
    {
         AdGroups adg = new AdGroups();
         adg.DomainGroup = ls[i].ToString();
         li.Add(adg);
    }
    
    return Json(li, JsonRequestBehavior.AllowGet);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 2018-04-09
      • 1970-01-01
      相关资源
      最近更新 更多