如何将模型列表数据绑定到mvc3中视图中的Jqgrid [英] How to bind Model List data to Jqgrid present in a view in mvc3

查看:68
本文介绍了如何将模型列表数据绑定到mvc3中视图中的Jqgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii to all,

我要求我需要使用Entity Framework在sqlserevr数据库中显示JqGrid中的表数据。我尝试使用ViewBag将数据绑定到JqGrid但是我无法满足我的要求,请帮助我如何使用ViewBag满足我的要求或提供任何其他替代方案来实现我的要求。

=>这是我的控制器代码: -

  public  ActionResult Index(TableData model)
{
// ViewBag.Message =欢迎使用ASP.NET MVC!;
员工empDetails = new Employee();
使用(personalEntities db = new personalEntities())
{
var emply =(来自 p db.empdetails
select p);

model.getobj = emply.ToList();
ViewBag.Name = model.getobj.ToList();
}
返回查看(模型);
}
=> 我的员工型号代码: -
public class 员工
{
public int EmployeeId { get ; set ; }
public string EmpName { get ; set ; }
public string 名称{ get ; set ; }
public int 薪资{ get ; set ; }
public int DeptNo { get ; set ; }
}
=> 我的TableData模型代码: -
public class TableData
{
public List< empdetail> getobj { get ; set ; }
}



=>这是我的查看代码: -

 @ model JQGrid .Models.TableData 
@ {
ViewBag.Title =主页;
}
var x = @ ViewBag.Name


< link href = @ Url.Content( 〜/ Content / themes / base / ui.jqgrid.css) rel = < span class =code-keyword> stylesheet type = text / css / >

< script src = < span class =code-keyword> @ Url.Content( 〜/ JS / jquery-1.7.2.min.js) < span class =code-attribute> type = text / javascript > < / script >
< script src = @ Url.Content( 〜/ JS / jquery.jqGrid.min.js) type = text / javascript > < / script >
< script src = @ Url.Content ( 〜/ JS / grid.locale-en.js) type = text / javascript > < / script >
< id = student-grid-array > < / table >
< script type = text / javascript >
$( #student-grid-array)。jqGrid( {
datatype: local
colNames:[ EmployeeID EmpName 名称 薪水 DeptNo],
colModel:[
{name: EmployeeID,index: EmployeeID},
{name: EmpName,index: EmpName},
{name: 名称,索引: 名称},
{名称: 薪水,索引: 薪水 ,sorttype: int},
{name: DeptNo,index: DeptNo,sorttype: int}
],
multiselect: true
shrinkToFit: false
标题: 员工列表 - 通过数组加载
});
for var i = 0 ; i< = x.length; i ++){
$( #student-grid-阵)addRowData(I,getobj [I])。
}
< / 脚本 >



在前三行(即在视图代码中)我试图将viewbag数据存储到某个变量x但我无法做到这一点,请指导我如何完成此任务,提前谢谢



谢谢

Ramu

解决方案

#student-grid-array)。jqGrid({
datatype: local
colNames:[ EmployeeID EmpName 名称 薪水 DeptNo],
colModel:[
{name: EmployeeID,index: EmployeeID},
{name: EmpName,index: EmpName},
{name: 名称,索引: 指定},
{名称: 薪水 ,index: 薪水,sorttype: int},
{name: DeptNo,索引: DeptNo,sorttype: int}
],
multiselect: true
shrinkToFit: false
caption: 员工列表 - 通过数组加载
});
for var i = 0 ; i< = x.length; i ++){


#学生栅阵列)addRowData(I,getobj [I])。
}
< / 脚本 >



在前三行(即在视图代码中)我试图将viewbag数据存储到某个变量x但我无法做到这一点,请指导我如何完成此任务,提前谢谢



谢谢

Ramu


hii to all,
I have requirement that i need to display a table data in JqGrid present in a sqlserevr database using Entity Framework.Iam trying with ViewBag to bind data to JqGrid but iam unable to meet my requirement,please help me how to meet my requirement using ViewBag or provide any other alternatives to achieve my requirement.
=>This is My Controller Code:-

public ActionResult Index(TableData model)
{
//ViewBag.Message = "Welcome to ASP.NET MVC!";
Employee empDetails = new Employee();
using (personalEntities db = new personalEntities())
{
var emply = (from p in db.empdetails
select p);

model.getobj = emply.ToList();
ViewBag.Name= model.getobj.ToList();
}
return View(model);
}
=>This is My Employee Model Code:-
public class Employee
{
public int EmployeeId { get; set; }
public string EmpName { get; set; }
public string Designation { get; set; }
public int Salary { get; set; }
public int DeptNo { get; set; }
}
=>This is My TableData Model Code:-
public class TableData
{
public List<empdetail> getobj { get; set; }
}


=>This is My View code:-

@model JQGrid.Models.TableData
@{
ViewBag.Title = "Home Page";
}
var x = @ViewBag.Name


<link href="@Url.Content("~/Content/themes/base/ui.jqgrid.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/JS/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/JS/jquery.jqGrid.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/JS/grid.locale-en.js")" type="text/javascript"></script>
<table id="student-grid-array"></table>
<script type="text/javascript">
$("#student-grid-array").jqGrid({
datatype: "local",
colNames: ["EmployeeID", "EmpName", "Designation", "Salary","DeptNo"],
colModel:[
{ name: "EmployeeID", index: "EmployeeID" },
{ name: "EmpName", index: "EmpName" },
{ name: "Designation", index: "Designation" },
{ name: "Salary", index: "Salary", sorttype: "int" },
{name:"DeptNo", index: "DeptNo",sorttype:"int"}
],
multiselect: true,
shrinkToFit: false,
caption: "Employee List - Loading via Array"
});
for (var i = 0; i <= x.length; i++) {
$("#student-grid-array").addRowData(i,getobj[i]);
}
</script>


In the top third line(i.e in view code) i tried to store viewbag data to some variable "x" but i was unable to do that,please guide me how to achieve this task,thanks in advance

Thanks
Ramu

解决方案

("#student-grid-array").jqGrid({ datatype: "local", colNames: ["EmployeeID", "EmpName", "Designation", "Salary","DeptNo"], colModel:[ { name: "EmployeeID", index: "EmployeeID" }, { name: "EmpName", index: "EmpName" }, { name: "Designation", index: "Designation" }, { name: "Salary", index: "Salary", sorttype: "int" }, {name:"DeptNo", index: "DeptNo",sorttype:"int"} ], multiselect: true, shrinkToFit: false, caption: "Employee List - Loading via Array" }); for (var i = 0; i <= x.length; i++) {


("#student-grid-array").addRowData(i,getobj[i]); } </script>


In the top third line(i.e in view code) i tried to store viewbag data to some variable "x" but i was unable to do that,please guide me how to achieve this task,thanks in advance

Thanks
Ramu


这篇关于如何将模型列表数据绑定到mvc3中视图中的Jqgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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