Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按结果从组中获取密钥_C#_Asp.net Mvc_View_Group By - Fatal编程技术网

C# 按结果从组中获取密钥

C# 按结果从组中获取密钥,c#,asp.net-mvc,view,group-by,C#,Asp.net Mvc,View,Group By,我有一个数据列表,我使用多个键对其应用了group by。我想每个td只检索一个密钥,但它会显示一个td中的所有密钥 我将如何实现这一点 这是我的密码 var _data = new List<Group<object, ShipWiseCargoHandling>>(); ViewBag.Print = Print; try { _output = _portSer.GetShipWiseCa

我有一个数据列表,我使用多个键对其应用了group by。我想每个td只检索一个密钥,但它会显示一个td中的所有密钥 我将如何实现这一点 这是我的密码

  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);
var_data=newlist();
ViewBag.Print=打印;
尝试
{
_输出=_portSer.GetShipWiseCargoHandling();
_数据=(来自q in_输出)
按新的{q.SHT_DESC,q.S_NAME,q.pqa_reg_no}将q分组为g
选择新组{Key=new{BerthName=g.Key.SHT_DESC,ShipName=g.Key.S_NAME,RegNo=g.Key.pqa_reg_no},Values=g}).ToList();
}
捕获(例外情况除外)
{
ViewBag.Message=“与服务器的连接不可用,请稍后再试!”+例如Message;
}
返回视图(_数据);
我以这种方式使用这个模型

  @foreach (var item in (List<Group<object, ShipWiseCargoHandling>>)Model)
        {
            <tr>
                <td>@Html.DisplayFor(model => item.Key)</td>
            </tr>
            foreach (var subitem in item.Values)
        {}}
@foreach(列表)模型中的变量项)
{
@DisplayFor(model=>item.Key)
foreach(item.Values中的var子项)
{}}

item.Key.bertname
Stephen it show me error您需要将
对象
更改为包含3个键(
bertname
等)的模型,您能给我看一个示例吗,因为键包含不同的数据类型不完全相同,但是应该有帮助-在您的情况下,视图模型还将包括集合的
IEnumerable
属性