代码之家  ›  专栏  ›  技术社区  ›  Eric Brown - Cal

让JQGrid格式化程序:showlink在MVC中工作

  •  8
  • Eric Brown - Cal  · 技术社区  · 17 年前

                    colModel: [
    
                      { name: 'RegName',  index: 'RegName', label: 'Region Name',width:90, align: 'center' },
                      { name: 'AccessNbr', index: 'AccessNbr', label: 'Access Number',width:80, align: 'center', formatter: 'showlink', formatoptions: {baseLinkUrl: '', showAction: 'GetBoxesForPorId', addParam: ''}  },
                      { name: 'TransmitedDt', index: 'TransmitedDt', label: 'TransmitedDt',  align: 'center' },
                      { name: 'BoxCount', index: 'BoxCount', label: 'Box Count', align: 'center' },
                      { name: 'PorId',  hidden:false ,index: 'PorId', label: 'Por ID', key:true ,formatter:'link', formatoptions: {target:'_new'}  }                           
                    ]
    

    http://localhost:4618/Por/GetBoxesForPorId?id=16

    http://localhost:4618/Por/GetBoxesForPorId/16

    2 回复  |  直到 13 年前
        1
  •  12
  •   Dan TheCodeJunkie    16 年前

    这是你的答案:

     function formateadorLink(cellvalue, options, rowObject) {
    
                return "<a href=/Idiomas/Edit/"+ cellvalue + ">" + cellvalue + "</a>";
            }
    

    在网格定义中:

       colModel: [
                            { name: 'id_idioma', index: 'id_idioma', width: 100, align: 'left',
                                formatter: formateadorLink
                            },
                            { name: 'nombre', index: 'nombre', width: 100, align: 'left' }
                      ],
    
        2
  •  1
  •   Sanchitos    16 年前

    我是这样做的:

      function LinkFormatter(cellvalue, options, rowObject) {
    
                return '<a href= <%= Url.Content("~/") %>' + cellvalue + ">Edit</a>";
            } 
    

    Col型号

      colModel: [
                        { name: 'Id', index: 'Id', width: 50, align: 'left', hidden: true },
                        { name: 'Edit', index: 'Edit', width: 50, align: 'left', formatter: LinkFormatter },
                        { name: 'AgentName', index: 'AgentName', width: 250, align: 'left' },
                        { name: 'AgentType', index: 'AgentType', width: 250, align: 'left' },
                    ],
    

    在服务器端

        var jsonData = new
        {
            total = 1,
            page = 1,
            records = agents.Count(),
            rows = (
                    from row in agents
                    select new
                    {
                        i = row.Id,
                        cell = new[] {
    
    
                            row.Id.ToString(),
                            "Controller/Action/" + row.Id.ToString(),
                            row.Name,
                            row.Type
                        }
                    }).ToArray()
    
        };