REVATHI R

REVATHI R

  • NA
  • 103
  • 3.3k

How to display large amount of records in grid from db

Nov 15 2017 6:36 AM
This is my source code,bt it won't run,i didn't know where to i mistake,,
Don't know that much of MVC,it shows an error records not found.
plz any one can help?
 
This is my controller
public ActionResult LoadData()
{
var Items = GetItems("", "", "");
return Json(new { data = Items }, JsonRequestBehavior.AllowGet);
}
private ActionResult GetItems(string PartNo, string Spec, string Desc)
{
try
{
GridWeb getgrid = new GridWeb();
List<DataItem1> gtcl = null;
gtcl = getgrid.LoadLargeRecd();
var Items = gtcl;
Items = Items.Where(x => x.Barcode.ToUpper().Contains(PartNo) || x.Manufacturer.ToUpper().Contains(Spec)|| x.ModelNumber.Contains(Desc)).ToList();
ViewBag.Items = Items;
return View(Items);
// Items = (Items
//.Where(x => x.Barcode.Contains(PartNo) && x.Manufacturer.Contains(Spec) && x.ModelNumber.Contains(Desc))).ToList();
}
 
Repository pattern
public string _conn = ConfigurationManager.ConnectionStrings["ConnStr"].ToString();
public List<DataItem1> LoadLargeRecd()
{
try
{
using (SqlConnection con = new SqlConnection(_conn))
{
con.Open();
string query1 = "select suid,Barcode,Manufacturer,ModelNumber from DataItem";
var res = con.Query<DataItem1>(query1);
return res.ToList();
}
}
 
This is my view
<script src="~/Scripts/jquery-1.12.0.js"></script>
<script src="~/Scripts/DataTables/jquery.dataTables.js"></script>
<script src="~/Scripts/DataTables/dataTables.jqueryui.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#tblItems tfoot th').each(function () {
var title = $(this).text();
$(this).html('<input class="FClass" style="width:inherit;" type="text" id="' + title.replace(' ', '_') + '" placeholder="Search ' + title + '" />');
});
var table = $('#tblItems').DataTable({
"ordering": false,
"processing": true,
"serverSide": true,
"lengthMenu": [[100, 250, 500, -1], [100, 250, 500, "All"]],
"pagingType": "full_numbers",
"scrollY": "350px",
"scrollX": true,
"ajax": {
"url": "/DataGrid/LoadData",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Barcode", "autoWidth": false },
{ "data": "Manufacturer", "autoWidth": true },
{ "data": "ModelNumber", "autoWidth": true },
]
});
 
model
[Display(Name = "Barcode")]
public string Barcode { get; set; }
public string Manufacturer { get; set; }
public string ModelNumber { get; set; }

Answers (3)