【问题标题】:Getting JQGrid formatter: ‘showlink’ to work in MVC让 JQGrid 格式化程序:'showlink' 在 MVC 中工作
【发布时间】:2009-09-11 22:05:36
【问题描述】:

我的栏目出现了,它正在为我的链接生成一个锚点。唯一的问题是 MVC 的 url 格式错误

这是 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'}  }                           
                ]

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

我希望它构建的网址是: http://localhost:4618/Por/GetBoxesForPorId/16

【问题讨论】:

标签: jquery asp.net-mvc jqgrid


【解决方案1】:

这是你的答案:

 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' }
                  ],

【讨论】:

  • 我可能会让你的答案更进一步:return '&lt;a href="&lt;%= Url.Action("Edit", "Idiomas") %&gt;/"' + cellValue + '"&gt;' + cellValue + '&lt;/a&gt;';
【解决方案2】:

我就是这样做的:

  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()

    };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多