c# - ASP.NET MVC/JqGrid : Is the JSON Id processed and recoverable?

标签 c# javascript json asp.net-mvc-3 jqgrid

我在多选模式下使用 JqGrid 并恢复用户的选择。 JqG​​rid 定义如下:

$("#StatusList").jqGrid({
         url: '@Url.Action("UpdateStatusList", "Inventory")',
         datatype: 'json',
         mtype: 'GET',
         colNames: ['Status', 'statusId'],
         colModel: [
          { name: 'Status', index: 'Status', align: 'left', sortable: false },
          { name: 'statusId', index: 'statusId', hidden: true}]
});

我对服务器和客户端之间的所有通信没有任何问题。一切正常。但是我觉得在使用发送 JSON 数据的函数填充 JqGrid 时我在复制数据:

  public ActionResult UpdateStatusList()
  {
     var jsonData = new
     {
        rows = (from status in DatabaseInMemory.WoodStatus.GetEntities()
                select new
                {
                   i = status.ID,
                   cell = new string[] { status.Name,
                              status.ID.ToString() }
                }).ToArray()
     };
     return Json(jsonData, JsonRequestBehavior.AllowGet);
  }

如您所见,id 被传递了两次: - 对于 JSON ID。 - 用于帮助我从网格中恢复 ID 的隐藏列。

返回客户端,JSON Id 不保存在 selarrrow 属性中。此属性根据网格中的位置保存 id。我正在使用它来获取选定的数据,并恢复真实的 ID。

JqGrid 是否处理并保存通过 JSON 数据传递的 id,或者它是否丢失并且始终需要一个隐藏列来跟踪行?

最佳答案

您应该将 i = status.ID 更改为 id = status.ID

关于c# - ASP.NET MVC/JqGrid : Is the JSON Id processed and recoverable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7107916/

相关文章:

c# - Glimpse WebAPI 支持

c# - EF5 和分离的 POCO,导航属性返回 null

java - Spring RestTemplate 解析具有可变键名的 JSON 对象

android - Json 数组解析在 Android 中总是有 null 结果

c# - 我无法从我的 ASP.NET MVC3 ViewModel 中获取月、日、年下拉列表

c# - 使用任意字符串向左或向右填充 string.format(不是 padleft 或 padright)

javascript - 下拉菜单悬停类未删除

javascript - 使用 Javascript 重新加载 HTML Img 标签

javascript - Headless Chrome 和 document.location.href 更改

c# - .NET Core - 读取 JSON 文件的转换日期