如何获得sord,sidx,page,rows,_serach值到控制器

时间:2013-08-23 12:02:38

标签: jquery asp.net-mvc asp.net-mvc-4 razor jqgrid

在调用控制器时,我从JQ Grid获取字段sord,sidx,page,rows,_serach等的空值。我已经发布了我的代码。我需要对服务器端编码进行排序,搜索并动态设置rownum计数。非常感谢。

代码:

<script type="text/javascript">
    function displayGrid() {
        $("#JQGridServerSideTable").jqGrid({
             width: 750,
            height: '100%',
            url: '@Url.Action("ServerSideJqGridProcessing", "JQGridHome")',
            datatype: 'json',
            mtype: "GET",
            colNames:  ["Application ID", "TenantId", "Application Name"],
            colModel: [
            { name: 'AppId', index: 'AppId', hidden: false },
            { name: 'TenantId', index: 'TenantId', resizable: true, align: 'center', title: false, editable: true, sortable: true, searchoptions: { sopt: ['eq', 'ne', 'le', 'lt', 'gt', 'ge'] }, searchtype: "number",editrules: {required: true, number: true} },
            { name: 'AppName', index: 'AppName', sortable: true, editable: true,editrules: {required: true} },
            ],  
            rowNum: 10,
            rowList: [5, 10, 20, 30],
            pager: '#JQGridServerSidePaging',
            viewrecords: true,
            caption: "Application List Details",
            sortname: "TenantId",
            sortorder: "asc",
            hoverrows: true,
            altRows:true,
            altclass:'myAltRowClass',
            hidegrid: true,
            toppager: false,
            multiselect: false,
            shrinkToFit: true,
            emptyrecords: "No records to view",
            loadtext:'Loading Data please wait ...'

        });
        $("#JQGridServerSideTable").jqGrid('navGrid', '#JQGridServerSidePaging',
             {
                refresh: false, add: false, edit: false, del: false, search: true,
                searchtext: "Search",
             },
             {},
             {},{},

             {
              sopt: ['eq', 'cn', 'lt', 'le', 'bw', 'bn', 'in'], closeOnEscape: true, multipleSearch: true, overlay: true, width: 460, closeAfterSearch: true }
         );
    }

    $(document).ready(function () {
        displayGrid();
    });
</script>

控制器:

public ActionResult ServerSideJqGridProcessing(string sidx, string sord, int page, int rows, bool _search, string searchField, string searchOper, string searchString)
{
     AllApps o = new AllApps();
     ApplicationModel appModelObj = new ApplicationModel();
     List<AppList> groups = o.getAllAppList();
     List<AppList> result = null;
     if (_search)
     {
         result = groups.Where(x => x.AppName.Contains(searchString)).ToList();
     }
     else
     {
         result = groups.Skip(page * rows).Take(rows).ToList();
     }
     int i = 1;
     var jsonData = new { 
         total = groups.Count,
         page = page,
         records = groups.Count,
         rows = (from appgroup in result
                 select new {
                     i=i++,
                     cell = new string[]{appgroup.AppName,appgroup.AppId.ToString(),appgroup.TenantId.ToString()}
                 }).ToArray()
     };
     int TotalCount = appModelObj.AllApplicationList.Count;
     return Json(jsonData);
}

0 个答案:

没有答案