Ranjitha M

Ranjitha M

  • NA
  • 21
  • 6.8k

pagination in mvc

Jul 20 2017 1:04 AM
I am Ranjitha ,i am able to display data in gridview ,can anyone let me know how to do pagination in mvc . iam posting my code if any changes are can u let me know.
 
default1 controller
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PERFJQGIRD.Controllers;
using PERFJQGIRD.Models;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;
namespace PERFJQGIRD.Controllers
{
public class Default1Controller : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetData(string ReleaseId, string ReleaseName, string Scopelockdate, string ReleaseDate, string Segment, string Query, string Status)
{
List<Class1> ObjClass = new List<Class1>();
// MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
// con.Open();
// MySqlCommand cmd = new MySqlCommand();
// cmd.CommandText = "getReleaseDetails";
//cmd.CommandType = CommandType.StoredProcedure;
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM tfsperfqueue", con);
//MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adp.Fill(ds);
//cmd.Dispose();
//con.Close();
//return Json(ObjClass, JsonRequestBehavior.AllowGet);
var model = new List<Class1>();
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var release1 = new Class1();
release1.ReleaseId = Convert.ToInt32(rdr["Release_Id"]);
release1.ReleaseName = Convert.ToString(rdr["Release_Name"]);
release1.Scopelockdate = Convert.ToDateTime(rdr["Scope_lock_date"]);
release1.Releasedate = Convert.ToDateTime(rdr["Release_Date"]);
release1.Segment = Convert.ToString(rdr["Segment"]);
release1.Query = Convert.ToString(rdr["Query"]);
release1.Status = Convert.ToInt32(rdr["Status"]);
model.Add(release1);
}
return Json(model, JsonRequestBehavior.AllowGet);
}
}
}
 
 
Index
 
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<link rel="stylesheet" href="~/styles/layout.css" type="text/css" />
<link href="~/styles/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/JQGrid/jquery-1.11.0.min.js"></script>
<script src="~/Scripts/JQGrid/jquery.jqGrid.min.js"></script>
<script src="~/Scripts/JQGrid/grid.locale-en.js"></script>
<link href="~/styles/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<div class="wrapper">
<div class="container">
<div class="content">
<table id="tblJQGrid"></table>
<br />
<table id="listPager"></table>
</div>
<br class="clear" />
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {

$("#tblJQGrid").jqGrid(

{
url: 'GetData/Default1',
datatype: "json",
mtype: 'GET',
colNames: ['ReleaseId', 'ReleaseName', 'Scopelockdate', 'Releasedate', 'Segment', 'Query', 'Status'],
colModel: [
{ name: 'ReleaseId', index: 'ReleaseId', width: 80, stype: 'text' },
{ name: 'ReleaseName', index: 'ReleaseName', width: 150 },
{ name: 'Scopelockdate', index: 'Scopelockdate', width: 150 },
{ name: 'Releasedate', index: 'Releasedate', width: 80, align: "right" },
{ name: 'Segment', index: 'Age', width: 80, align: "right" },
{ name: 'Query', index: 'Query', width: 80, align: "right" },
{ name: 'Status', index: 'Status', width: 150,align: "right", sortable: false }],
rowNum: 10,
rowList: [10, 20, 30],
pager: "#listPager",
sortname: 'ReleaseId',
viewrecords: true,
sortorder: "desc",
caption: "List Relesae Details",
scrollOffset: 0
});
});
</script>
 
 
 

Answers (2)