Obtenir le formateur JQGrid: & # 8216; showlink & # 8217; travailler chez MVC
-
06-07-2019 - |
Question
Mes colonnes apparaissent, cela génère une ancre pour mon lien. Le seul problème est que l’URL est mal formé pour MVC
Voici le 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'} }
]
Voici l'URL qu'il construit: http: // localhost: 4618 / Por / GetBoxesForPorId? id = 16
L'URL que je souhaite créer est: http: // localhost: 4618 / Por / GetBoxesForPorId / 16
La solution
Voici votre réponse:
function formateadorLink(cellvalue, options, rowObject) {
return "<a href=/Idiomas/Edit/"+ cellvalue + ">" + cellvalue + "</a>";
}
dans la définition de la grille:
colModel: [
{ name: 'id_idioma', index: 'id_idioma', width: 100, align: 'left',
formatter: formateadorLink
},
{ name: 'nombre', index: 'nombre', width: 100, align: 'left' }
],
Autres conseils
Voici comment je l'ai fait:
function LinkFormatter(cellvalue, options, rowObject) {
return '<a href= <%= Url.Content("~/") %>' + cellvalue + ">Edit</a>";
}
Modèle de 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' },
],
Du côté du serveur
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()
};
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow