简体   繁体   English

使用ASP.NET MVC的jqgrid列linq

[英]jqgrid column linq with ASP.NET MVC

I have a class (Person) with 4 properties : Id, FirstName, LastName, Code. 我有一个具有4个属性的类(人):Id,FirstName,LastName,Code。

I show a person list in a jqgrid. 我在jqgrid中显示人员列表。 I'd like a link column with this format (the code has this format 2011.0001) 我想要具有此格式的链接列(代码具有此格式2011.0001)

/Person/Detail/Code => /Person/Code/2011.0001 /人/详细信息/代码=> /人/代码/2011.0001

But I have this with the code below : /Customer/Detail?Code=2 但是我有下面的代码:/ Customer / Detail?Code = 2

I tried this : 我尝试了这个:

colModel: [
    { name: 'Code', index: 'Code', formatter: 'showlink', formatoptions: { baseLinkUrl: '/Customer/Detail', idName: 'Code' }},
    { name: 'LastName', index: 'LastName', align: 'left' },
    { name: 'FirstName', index: 'FirstName', align: 'left' }                  
],

How can I correct this ? 我该如何纠正?

Thanks, 谢谢,

Update1, Data format Update1,数据格式

[
{"Id":1,"FirstName":"AAAA","LastName":"AA","Code":"2011.0001"},
{"Id":3,"FirstName":"BBBB","LastName":"BB","Code":"2011.0003"}
]

You can try to use the custom formatter in the form 您可以尝试在表单中使用自定义格式化程序

formatter: function (cellvalue, options, rowObject) {
    return '<a href="/Person/Code/' + rowObject.Code + '">' + cellvalue + '</a>';
}

instead of predefined formatter 'showlink': 而不是预定义的格式化程序 “ showlink”:

formatter: 'showlink', formatoptions: {baseLinkUrl:'/Customer/Detail', idName:'Code'}

You can easy receive /Customer/Detail?Code=2011.0001 if you have unique data in the 'Code' column and if you would add key: true to the column definition. 如果您在“代码”列中具有唯一数据,并且要在列定义中添加key: true ,则可以轻松接收/Customer/Detail?Code=2011.0001 In the case the Id value from the JSON input will be ignored and the value from the 'Code' column will be used as the rowid. 如果来自JSON输入的Id值将被忽略,而来自“代码”列的值将用作行ID。 If you do need to have the href value in the form /Customer/Detail/Code/2011.0001 or instead of /Customer/Detail?Code=2011.0001 you will need use custom formatter as I described before. 如果您确实需要用/Customer/Detail/Code/2011.0001形式的href值,或者代替/Customer/Detail?Code=2011.0001href值,则需要使用自定义格式化程序,如我之前所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM