Created
          August 17, 2015 11:59 
        
      - 
      
 - 
        
Save cynx/fd01208f1a78a057dc09 to your computer and use it in GitHub Desktop.  
    HomeController.cs file for the JQUERY DATATABLES 1.10+ AND ASP.NET MVC 5 SERVER SIDE INTEGRATION
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Web; | |
| using System.Web.Mvc; | |
| using MVCDatatableApp.Models; | |
| namespace MVCDatatableApp.Controllers | |
| { | |
| public class HomeController : Controller | |
| { | |
| public ActionResult Index() | |
| { | |
| return View(); | |
| } | |
| public JsonResult DataHandler(DTParameters param) | |
| { | |
| try | |
| { | |
| var dtsource = new List<Customer>(); | |
| using (dataSetEntities dc = new dataSetEntities()) | |
| { | |
| dtsource = dc.Customers.ToList(); | |
| } | |
| List<String> columnSearch = new List<string>(); | |
| foreach (var col in param.Columns) | |
| { | |
| columnSearch.Add(col.Search.Value); | |
| } | |
| List<Customer> data = new ResultSet().GetResult(param.Search.Value, param.SortOrder, param.Start, param.Length, dtsource, columnSearch); | |
| int count = new ResultSet().Count(param.Search.Value, dtsource, columnSearch); | |
| DTResult<Customer> result = new DTResult<Customer> | |
| { | |
| draw = param.Draw, | |
| data = data, | |
| recordsFiltered = count, | |
| recordsTotal = count | |
| }; | |
| return Json(result); | |
| } | |
| catch (Exception ex) | |
| { | |
| return Json(new { error = ex.Message }); | |
| } | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
There is a minor issue with the recordsFiltered / recordsTotal counters
If
recrodsFilteredandrecordsTotalare equal, theoLanguage: sInfoFileredtext from the DataTable will never show up. I think thatrecordsTotalshould be equal todtsource.Count()so that you can show something line "Showing 1 to 10 from 128 entries (filtered from 35978 recrods) " so that in all cases you can see how many total records you have, how many match the filter.