Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3 JQGrid
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
Posted 13-May-13 22:03pm
Edited 13-May-13 23:02pm
(no name)105.8K
v2
Comments
Kenneth Haugland at 14-May-13 3:11am
   
You should fix the formatting.
rajacsharp5 at 11-Oct-13 9:08am
   
hey you just go the msdn stuart given about asp.net mvc grid.
Ram7 from Hyderabad at 14-May-13 3:19am
   
Can you please explain in detail how to fix the formatting,as iam new to MVC
T.Saravanann at 25-Oct-13 3:17am
   
If I need to get the department name from another table by having a reference with that department number, how can I achieve that?
Kenneth Haugland at 14-May-13 4:02am
   
Like I have done now :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 320
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 184
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100