从结果分组中获取密钥

时间:2018-10-24 09:09:00

标签: c# asp.net-mvc view group-by

我有一个数据列表,我使用多个键对它们进行了分组。我想每td只检索一个密钥,但是它显示了我在一td中的所有密钥 我将如何实现 这是m代码

  var _data = new List<Group<object, ShipWiseCargoHandling>>();

        ViewBag.Print = Print;
        try
        {
            _output = _portSer.GetShipWiseCargoHandling();
             _data = (from q in _output
            group q by new { q.SHT_DESC ,q.S_NAME,q.pqa_reg_no} into g
            select new Group<object, ShipWiseCargoHandling> { Key=new {BerthName= g.Key.SHT_DESC,ShipName=g.Key.S_NAME,RegNo=g.Key.pqa_reg_no}, Values = g }).ToList();

        }
        catch (Exception ex)
        {
            ViewBag.Message = "Connectivity to server is not available, Please try it later! " + ex.Message;                
        }
        return View(_data);

我以这种方式使用此模型

  @foreach (var item in (List<Group<object, ShipWiseCargoHandling>>)Model)
        {
            <tr>
                <td>@Html.DisplayFor(model => item.Key)</td>
            </tr>
            foreach (var subitem in item.Values)
        {}}

0 个答案:

没有答案