JSON数据不会进入网格 [英] JSON Data is not coming in the Grid
问题描述
Hello All,
我有一个难以用JSON格式实现Jqgrid。我可以看到网格,但数据并没有感觉到。
这是代码。
查看:
@model POC.Models.AccoundMedViewModels
@ {
ViewBag.Title =JQGrid实施;
}
@section MyScript {
<! - JQuery CSS - >
< link rel =stylesheethref = 〜/ Content / jquery-ui.csstype =text / css/>
<! - jqGrid CSS - >
< link rel =stylesheethref =〜/ Content / ui.jqgrid.csstype =text / css/>
<! - 实际的JQuery代码 - >
< script type =text / javascriptsrc =〜/ Scripts / jquery-1.10.2.js>< / script>
< ! - JQuery UI代码 - >
< script type =text / javascriptsrc =〜/ Scripts / jquery-ui.min.js>< / script> ;
<! - jqGrid语言文件代码 - >
< script type =text / javascriptsrc =〜/ Scripts / grid。 locale-en.js>< / script>
<! - atq jqGrid代码 - >
< script type =text / javascriptsrc =〜/ Scripts / jquery.jqGrid.src.js>< / script>
<! - 迁移一个 - >
< script type =text / javascriptsrc =〜/ Scripts / jquery-migrate-1.2.1。 js>< / script>
}
JQGrid实施
@section scripts {
< script type =text / javascript>
$(document).ready(function(){
$(#jqGrid)。jqGrid({
url: '@ Url.Action(GetData,AccountMed)',
mtype:'GET',
数据类型:'json',
jsonReader:{
root:rows,
id:id,
cell:cell,
页:page,
总计:total,
FirstName:FirstName,
LastName:LastName,
repeatitems:true,
记录:记录,
userdata:userdata
},
colNames:['FirstName','LastName'],
colModel:[
{name:'FirstName',index:'FirstName',width:75},
{name:'LastName',index:'LastName',width:150 },
],
viewrecords:true,
宽度:780,
身高:250,
rowNum:20,
寻呼机:'#jqGridPager'
});
});
< / script>
}
< br $>
控制器方法:
public JsonResult GetData()
{
List< Employee> e =新列表< Employee>();
e。添加(新员工()
{
FirstName = Gaurav,
LastName = 萨穆德拉
});
e。添加(新员工()
{
FirstName = Akruti,
LastName = Patel
});
return Json(e,JsonRequestBehavior.AllowGet);
}
请帮帮我。任何帮助都将受到高度赞赏。
(document).ready(function(){
( #jqGrid)。jqGrid({
url:'@ Url.Action(GetData,AccountMed)',
mtype:'GET',
数据类型:'json',
jsonReader:{
root:rows,
id:id,
cell:cell,
page:page,
总计:总计,
FirstName:FirstName,
姓氏:LastName,
repeatitems:true,
记录:记录,
userdata:userdata
},
colNames:['FirstName '' LastN ame'],
colModel:[
{name:'FirstName',index:'FirstName',width:75},
{名称:'LastName',索引:'LastName',宽度:150},
],
viewrecords:true,
宽度:780 ,
身高:250,
rowNum:20,
寻呼机:'#jqGridPager'
});
});
< / script>
} < br $>
控制器方法:
public JsonResult GetData()
{
List< Employee> e =新列表< Employee>();
e。添加(新员工()
{
FirstName = Gaurav,
LastName = 萨穆德拉
});
e。添加(新员工()
{
FirstName = Akruti,
LastName = Patel
});
return Json(e,JsonRequestBehavior.AllowGet);
}
请帮帮我。任何帮助都将受到高度赞赏。
我认为控制器的结果集未映射到网格。请在控制器端尝试以下内容并告诉我。
public ActionResult GetData(GridSettings gridSettings)
{
列表与LT;雇员> e = new 列表< employee>();
e.Add( new Employee()
{
FirstName = Gaurav,
LastName = 萨穆德拉
});
e.Add( new Employee()
{
FirstName = Akruti,
LastName = Patel
});
var jsonData = new
{
total = e.Count()/ gridSettings.PageSize + 1 ,
page = gridSettings.PageIndex,
records = e.Count(),
rows =(
来自 c e
选择 new
{
identifier
cell = new []
{
c.FirstName,
c.LastName
}
})。ToArray()
};
return Json(jsonData,JsonRequestBehavior.AllowGet);
} < / 员工 > < / 员工 >
Hello All,
I am having one difficulty to implement Jqgrid with JSON format. I can see the Grid but, data is not feeling out.
Here is the code.
View:
@model POC.Models.AccoundMedViewModels
@{
ViewBag.Title = "JQGrid Implementation";
}
@section MyScript{
<!-- JQuery CSS -->
<link rel="stylesheet" href="~/Content/jquery-ui.css" type="text/css" />
<!-- jqGrid CSS -->
<link rel="stylesheet" href="~/Content/ui.jqgrid.css" type="text/css" />
<!-- The actual JQuery code -->
<script type="text/javascript" src="~/Scripts/jquery-1.10.2.js"></script>
<!-- The JQuery UI code -->
<script type="text/javascript" src="~/Scripts/jquery-ui.min.js"></script>
<!-- The jqGrid language file code-->
<script type="text/javascript" src="~/Scripts/grid.locale-en.js"></script>
<!-- The atual jqGrid code -->
<script type="text/javascript" src="~/Scripts/jquery.jqGrid.src.js"></script>
<!--Migrated one-->
<script type="text/javascript" src="~/Scripts/jquery-migrate-1.2.1.js"></script>
}
JQGrid Implementation
@section scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#jqGrid").jqGrid({
url: '@Url.Action("GetData", "AccountMed")',
mtype: 'GET',
datatype: 'json',
jsonReader: {
root: "rows",
id: "id",
cell: "cell",
page: "page",
total: "total",
FirstName: "FirstName",
LastName: "LastName",
repeatitems: true,
records: "records",
userdata:"userdata"
},
colNames:['FirstName','LastName'],
colModel: [
{ name: 'FirstName', index: 'FirstName', width: 75 },
{ name: 'LastName', index: 'LastName', width: 150 },
],
viewrecords: true,
width: 780,
height: 250,
rowNum: 20,
pager: '#jqGridPager'
});
});
</script>
}
Controller Method:
public JsonResult GetData()
{
List<Employee> e = new List<Employee>();
e.Add(new Employee()
{
FirstName = "Gaurav",
LastName = "Samudra"
});
e.Add(new Employee()
{
FirstName = "Akruti",
LastName = "Patel"
});
return Json(e, JsonRequestBehavior.AllowGet);
}
Please help me with this. Any help would be highly appreciated.
(document).ready(function () {
("#jqGrid").jqGrid({
url: '@Url.Action("GetData", "AccountMed")',
mtype: 'GET',
datatype: 'json',
jsonReader: {
root: "rows",
id: "id",
cell: "cell",
page: "page",
total: "total",
FirstName: "FirstName",
LastName: "LastName",
repeatitems: true,
records: "records",
userdata:"userdata"
},
colNames:['FirstName','LastName'],
colModel: [
{ name: 'FirstName', index: 'FirstName', width: 75 },
{ name: 'LastName', index: 'LastName', width: 150 },
],
viewrecords: true,
width: 780,
height: 250,
rowNum: 20,
pager: '#jqGridPager'
});
});
</script>
}
Controller Method:
public JsonResult GetData() { List<Employee> e = new List<Employee>(); e.Add(new Employee() { FirstName = "Gaurav", LastName = "Samudra" }); e.Add(new Employee() { FirstName = "Akruti", LastName = "Patel" }); return Json(e, JsonRequestBehavior.AllowGet); }
Please help me with this. Any help would be highly appreciated.
I think the result set from the controller is not mapped to the grid.Please try the following in the controller side and let me know.
public ActionResult GetData(GridSettings gridSettings) { List<employee> e = new List<employee>(); e.Add(new Employee() { FirstName = "Gaurav", LastName = "Samudra" }); e.Add(new Employee() { FirstName = "Akruti", LastName = "Patel" }); var jsonData = new { total = e.Count()/ gridSettings.PageSize + 1, page = gridSettings.PageIndex, records = e.Count(), rows = ( from c in e select new { identifier cell = new[] { c.FirstName, c.LastName } }).ToArray() }; return Json(jsonData, JsonRequestBehavior.AllowGet); }</employee></employee>
这篇关于JSON数据不会进入网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!