Ranjitha M

Ranjitha M

  • NA
  • 21
  • 6.9k

pagination in mvc using mysql workbench

Jul 18 2017 12:53 AM
hi iam Ranjitha iam doing a project on mvc , in my project iam able to display the data from mysql ,here what i want is ,how to do pagenation in mvc by using mysql database,can any one help me ,i have posted my code also.
 
Default controller
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;
using Getqueuedetails.Models;
using Getqueuedetails.Controllers;
namespace GetData.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<Release> ObjClass = new List<Release>();
// 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<Release>();
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var release1 = new Release();
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.cshtml
 
@{
ViewBag.Title = "Index";
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$.getJSON("GetData/Default1",
function (json) {
var tr;
//Append each row to html table
for (var i = 0; i < json.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + json[i].ReleaseId + "</td>");
tr.append("<td>" + json[i].ReleaseName + "</td>");
tr.append("<td>" + json[i].Scopelockdate + "</td>");
tr.append("<td>" + json[i].Releasedate + "</td>");
tr.append("<td>" + json[i].Segment + "</td>");
tr.append("<td>" + json[i].Query + "</td>");
tr.append("<td>" + json[i].Status + "</td>");
$('table').append(tr);
}
});
});
$.ajax(
{
type: "Get", //HTTP POST Method
url: '@Url.Action("GetData","Default")', // Controller/View
//method: 'Post',
dataType: "json",
contentType: 'application/json',
success: function () {

//window.location.href = '/Default1/Insert';
},
//window.location.href = '/Default1/Insert';

error: function (error) {
alert(error)
}
});
</script>
<table class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>ReleaseId</th>
<th>ReleaseName</th>
<th>Scopelockdate</th>
<th>Releasedate</th>
<th>Segment</th>
<th>Query</th>
<th>Stauts</th>

</tr>

</thead>

<tbody></tbody>
</table>
 
 
 
 
 
 
 

Answers (1)