Esempio n. 1
0
        public ActionResult PageData(IDataTablesRequest request)
        {
            // Nothing important here. Just creates some mock data.
            var data = AccessLevel.GetData();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = data.Where(_item =>
                                          _item.AccessLevelID.ToString().Contains(request.Search.Value) ||
                                          _item.LevelName.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                          _item.LevelDescription.ToUpper().Contains(request.Search.Value.ToUpper())
                                          );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }