Example #1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;


            //   var valueResultProvider = valueProvider.GetValue("draw");
            if (valueProvider == null)
            {
                return(null);
            }

            //TryParse<int>(valueResultProvider, out draw);
            TryParse <int>(valueProvider.GetValue("draw"), out int draw);
            TryParse <int>(valueProvider.GetValue("start"), out int start);
            TryParse <int>(valueProvider.GetValue("length"), out int length);

            DataTablesRequest result = new DataTablesRequest(draw, start, length, TryGetSearch(valueProvider),
                                                             TryGetOrders(valueProvider), TryGetColumns(valueProvider));

            return(result);
        }
        /// <summary>
        /// Gets a <see cref="DataTablesResponse{T}"/> from collection/request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="request"></param>
        /// <param name="recordsTotal">Number of records before filtered</param>
        /// <param name="recordsFiltered">Number of records after filtered</param>
        /// <returns></returns>
        public static DataTablesResponse <T> ToDataTablesResponse <T>(this IEnumerable <T> collection, DataTablesRequest request, int recordsTotal, int recordsFiltered)
        {
            DataTablesResponse <T> response = new DataTablesResponse <T>
            {
                draw            = request.Draw,
                recordsTotal    = recordsTotal,
                recordsFiltered = recordsFiltered,
                data            = collection
            };

            return(response);
        }