首页 文章

在通过JQ Grid进行搜索时,不会调用Action类

提问于
浏览
0

我正在使用MVC 2.0 Web应用程序,其中有几个按钮,其onclick我称之为动作方法,但是当我第一次按下搜索按钮时,动作方法被调用但是之后如果我尝试单击搜索按钮,则动作方法是没有被召唤 .

另外,让我告诉您,我正在使用JQ Grid在按钮onclick上显示数据 . 请参阅下面的代码段 .

function LoadGrid(data,type){

var showGrid = $("#showGrid");
        var navigation = $("#navigation");

        showGrid.jqGrid({
            url: '/Customer/CustomerSearchInfo',
            datatype: 'json',
            mtype: 'POST',
            cache: false,
            postData: { param: data, type: type },

            colNames: ['Customer Name', 'Contact Name', 'Company Number', 'Customer Number', 'Link Number', 'Phone', 'SalesRep Name', 'Sequence'],
            colModel: [
              { name: 'COMPANY_NAME', index: '1', align: 'left', sortable: true },
              { name: 'CONTACT_NAME', index: '2', align: 'left', sortable: true },
              { name: 'COMPANY_NUM', index: '3', align: 'left', sortable: true },
              { name: 'CUSTOMER_NUM', index: '4', align: 'left', sortable: true },
              { name: 'LINK_NUM', index: '5', align: 'left', sortable: true },
              { name: 'PHONE_1', index: '6', align: 'left', sortable: true },
              { name: 'SALESREP_NUM', index: '7', align: 'left', sortable: true },
              { name: 'ADDRESS_SEQ_NUM', index: '8', align: 'left', sortable: true }
             ],
            pager: navigation,
            rowNum: 10,
            rowList: [5, 10, 20, 30, 50],
            viewrecords: true,
            caption: '',
            height: '250px',
            sortorder: 'asc',
            sortname: '0',
            shrinkToFit: true,
            autowidth: true,
             }
        })

    };

提到的操作方法(/ Customer / CustomerSearchInfo)第二次没有被调用 .

[AcceptVerbs(HttpVerbs.Post)] public ActionResult CustomerSearchInfo(string param,int type){

try
        {
            var custInfo = new List<Customer>();
            switch (type)
            {
                case 1:
                    custInfo = custDO.GetCustomerInfo(customerID: param);
                    break;
                case 2:
                    custInfo = custDO.GetCustomerInfo(customerName: param);
                    break;
                case 3:
                    custInfo = custDO.GetCustomerInfo(contactName: param);
                    break;
                case 4:
                    custInfo = custDO.GetCustomerInfo(companyID: param);
                    break;
                case 5:
                    custInfo = custDO.GetCustomerInfo(salesRepID: param);
                    break;
                case 6:
                    custInfo = custDO.GetCustomerInfo(phone: param);
                    break;
                case 7:
                    custInfo = custDO.GetCustomerInfo(addrtype: param);
                    break;
                case 8:
                    custInfo = custDO.GetCustomerInfo(status: param);
                    break;
                case 9:
                    custInfo = custDO.GetCustomerInfo(linkID: param);
                    break;
            }

                            return custInfo != null
                       ? Json(GetJson(custInfo, 10, custInfo.Count, 0),
                              JsonRequestBehavior.DenyGet)
                       : Json(null, JsonRequestBehavior.DenyGet);
        }
        catch (Exception ex)
        {
            Response.StatusCode = 500;
            return Json(null, JsonRequestBehavior.DenyGet);
        }


    }

以下是2个搜索按钮:

input id =“btnCustID”type =“button”class =“buttonsearch”title =“按客户ID搜索”onclick =“LoadGrid(document.getElementById('txtCustID') . value,1)”

input id =“btnCustName”type =“button”class =“buttonsearch”title =“按客户名称搜索”onclick =“LoadGrid(document.getElementById('txtCustName') . value,2)”

2 回答

  • 0

    您的JavaScript无效,因为您正在尝试重新初始化已初始化的jqGrid . 你可以做的事情很少 .

    您可以在再次初始化之前卸载jqGrid(下载网格时需要标记Custom复选框):

    var showGrid = $("#showGrid");
    var navigation = $("#navigation");
    
    showGrid.jqGrid('GridUnload');
    ...
    

    您可以更改postData并重新加载您的jqGrid而无需重新初始化(您需要提前初始化它):

    var showGrid = $("#showGrid");
    showGrid.setPostData({ param: data, type: type });         
    showGrid.jqGrid('setGridParam', { page: 1 }).trigger("reloadGrid");
    

    或者您可以实现本机jqGrid搜索,这里有一些简单的描述:http://tpeczek.com/2009/11/jqgrid-and-aspnet-mvc-searching.html

  • 0

    我建议你安装Fiddler看看到底发生了什么;对于初学者:这是第二次提出的要求吗?它看起来像什么?

相关问题