获取JQGrid格式化程序:'showlink'在MVC中工作

Eri*_*Cal 7 asp.net-mvc jquery jqgrid

我的列正在显示,它正在为我的链接生成一个锚点.唯一的问题是网址很糟糕的MVC

这是colModel:

                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'}  }                           
                ]
Run Code Online (Sandbox Code Playgroud)

这是它构建的url: http:// localhost:4618/Por/GetBoxesForPorId?id = 16

我想要它构建的URL是: http:// localhost:4618/Por/GetBoxesForPorId/16

小智 12

这是你的答案:

 function formateadorLink(cellvalue, options, rowObject) {

            return "<a href=/Idiomas/Edit/"+ cellvalue + ">" + cellvalue + "</a>";
        }
Run Code Online (Sandbox Code Playgroud)

在网格定义中:

   colModel: [
                        { name: 'id_idioma', index: 'id_idioma', width: 100, align: 'left',
                            formatter: formateadorLink
                        },
                        { name: 'nombre', index: 'nombre', width: 100, align: 'left' }
                  ],
Run Code Online (Sandbox Code Playgroud)

  • 我可能会通过执行以下操作让您的答案更进一步:`return '&lt;a href="&lt;%= Url.Action("Edit", "Idiomas") %&gt;/"' + cellValue + '"&gt;' + cellValue + ' &lt;/a&gt;';` (2认同)