如何在MVC4.0中从Linq数据库设置jqgrid的colNames值 [英] how to set the value of colNames of jqgrid from Linq database in MVC4.0

查看:55
本文介绍了如何在MVC4.0中从Linq数据库设置jqgrid的colNames值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的.cshtml页面代码。在这里,我传递了colNames的硬编码值。问题是我想从数据库中获取这些值。



 jQuery(document).ready(function(){

var myGrid = $(' #jQGrid1 ');
myGrid.jqGrid({
height:' auto'
autowidth: true
标题: 声明
url:' Claim / GetRecords1 /'
数据类型: json
contentType:< span class =code-string> application / json; charset-utf-8
mtype:' POST',
colNames:[' ClaimId'' 客户名称' 金额'' 日期'' 已批准'],
colModel:[{name:' ClaimIde'},
{name:' CName'},
{name:' 金额'},
{ name:' Date'},
{name:' 已批准'}],
viewrecords: true
});

解决方案

' #jQGrid1');
myGrid.jqGrid({
height:' auto'
autowidth: true
caption: 声明
url:' Claim / GetRecords1 /'
数据类型: json
contentType: application / json; charset-utf-8
mtype:' POST'
colNames:[' ClaimId'' 客户名称' 金额'' 日期'' Approved'],
colModel:[{name:' ClaimIde' },
{name:' CName'},
{name:' 金额'},
{name:' Date'},
{name:' 已批准'}],
viewrecords: true
});


您必须进行jQuery Ajax调用,您将获得这些列名称作为json格式的数据,您可以使用这些数据为jQGrid设置列名。

This is my code of .cshtml page. Here I passed the hardcoded values of "colNames". Problem is I want to fetch that values from database.

jQuery(document).ready(function () {

       var myGrid = $('#jQGrid1');
       myGrid.jqGrid({
           height: 'auto',
           autowidth: true,
           caption: "Claim",
           url: 'Claim/GetRecords1/',
           datatype: "json",
           contentType: "application/json; charset-utf-8",
           mtype: 'POST',
           colNames: ['ClaimId', 'Customer Name', 'Amount', 'Date', 'Approved'],
           colModel: [{ name: 'ClaimIde' },
                       { name: 'CName' },
                       { name: 'Amount' },
                       { name: 'Date' },
                       { name: 'Approved'}],
           viewrecords: true,
       });

解决方案

('#jQGrid1'); myGrid.jqGrid({ height: 'auto', autowidth: true, caption: "Claim", url: 'Claim/GetRecords1/', datatype: "json", contentType: "application/json; charset-utf-8", mtype: 'POST', colNames: ['ClaimId', 'Customer Name', 'Amount', 'Date', 'Approved'], colModel: [{ name: 'ClaimIde' }, { name: 'CName' }, { name: 'Amount' }, { name: 'Date' }, { name: 'Approved'}], viewrecords: true, });


You have to make a jQuery Ajax call and you will get those column names as json formatted data which you can use to set the column names here for the jQGrid.


这篇关于如何在MVC4.0中从Linq数据库设置jqgrid的colNames值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆