2009-09-11 23 views
7

我的列正在顯示,它正在爲我的鏈接生成一個錨點。是URL格式錯誤的MVC獲取JQGrid格式:'showlink'在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'} }       
       ] 

下面是它建立的網址: http://localhost:4618/Por/GetBoxesForPorId?id=16

我想它來建立的網址是: http://localhost:4618/Por/GetBoxesForPorId/16

+0

可能複製http://stackoverflow.com/questions/1170510/asp-net-mvc-routing-with-jqgrid – Dan 2010-05-07 10:44:36

回答

12

這是你的答案:

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

我可能會採取更進一步的答案:'return'/"' + cellValue + '">' + cellValue + '';' – 2011-03-22 21:03:51

1

這是我做的方式:

function LinkFormatter(cellvalue, options, rowObject) { 

      return '<a href= <%= Url.Content("~/") %>' + cellvalue + ">Edit</a>"; 
     } 

山口型號

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

    };