Server processing with ASP.NET MVC

Server processing with ASP.NET MVC

Anhph68Anhph68 Posts: 1Questions: 0Answers: 0

Hi authors,

I want to implement jquery datatable with server processing in ASP.NET MVC project. How should I config the parameters in the server code. If I use the type of param of the old jquery datatable, it works perfectly.
This is my code:

public class DataTableParamModel
{
/// <summary>
/// Request sequence number sent by DataTable,
/// same value must be returned in response
/// </summary>
public string sEcho { get; set; }

    /// <summary>
    /// Text used for filtering
    /// </summary>
    public string sSearch { get; set; }

    /// <summary>
    /// Number of records that should be shown in table
    /// </summary>
    public int iDisplayLength { get; set; }

    /// <summary>
    /// First record that should be shown(used for paging)
    /// </summary>
    public int iDisplayStart { get; set; }

    /// <summary>
    /// Number of columns in table
    /// </summary>
    public int iColumns { get; set; }

    /// <summary>
    /// Number of columns that are used in sorting
    /// </summary>
    public int iSortingCols { get; set; }

    /// <summary>
    /// Comma separated list of column names
    /// </summary>
    public string sColumns { get; set; }

}

However, in the new type of the params of your plugin, it break down. Could you help me please?

public ActionResult GetAppList(DataTableParamModel param)
{
IEnumerable<tblApp> allResult = db.tblApps.ToList();

        IEnumerable<tblApp> filtered;

        var tmpCount = allResult.Count();

        if (!string.IsNullOrEmpty(param.sSearch))
        {
            //Optionally check whether the columns are searchable at all 
            var search0 = Convert.ToBoolean(Request["bSearchable_0"]);
            var search1 = Convert.ToBoolean(Request["bSearchable_1"]);
            var search2 = Convert.ToBoolean(Request["bSearchable_2"]);
            int tmp = int.TryParse(param.sSearch, out tmp) ? tmp : 0;

            allResult = allResult
                .Where(c => search1 && c.AppName.ToLower().Contains(param.sSearch.ToLower())
                         || search2 && c.AppUrl.ToLower().Contains(param.sSearch.ToLower())
                         || search0 && c.Id.Equals(tmp)
                 );
        }

        var result = allResult.Select(c => new
        {
            col0 = c.Id,
            col1 = c.AppName,
            col2 = c.AppUrl
        });

        return Json(new
        {
            sEcho = param.sEcho,
            iTotalRecords = allResult.Count(),
            iTotalDisplayRecords = allResult.Count(),
            aaData = result
        }, JsonRequestBehavior.AllowGet);
    }

sSearch always is null. What should I config?

This discussion has been closed.