ASP.NET MVC3中的JQuery Grid [英] JQuery Grid in ASP.NET MVC3

查看:47
本文介绍了ASP.NET MVC3中的JQuery Grid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将上面的代码用于我的应用程序,它有一个Jquery网格。我在我的jquery Grid中导出到excel按钮但是当我点击导出到excel按钮时,我在其中一个类文件(ControllerFactory.cs)中获得一个异常,该文件用于路由到适当的控制器名称和操作名称。我调试应用程序,我发现对于其他选项,如gridView中的Reload Grid,ControllerFactory.cs正在获取正确的控制器和操作名称,但是为了导出到excel按钮,它将获得包含控制器名称的controllertype变量的空值。请找到我的controllerfactory代码





I have used the above code for my application which is having a Jquery grid. I am getting export to excel button in my jquery Grid but when i am clicking the export to excel button i am getting an exception in one of the class file(ControllerFactory.cs) which is used for routing to appropriate controller name and action name. I debug the application and i found that for others option like Reload Grid in gridView the ControllerFactory.cs is getting correct controller and action name but for export to excel button it is getting null value for controllertype variable which contains the controller name. please find my controllerfactory code


public class UPControllerFactory : DefaultControllerFactory
{
    protected override IController GetControllerInstance(RequestContext requestContext,
                                                    Type controllerType)
    {
        if (requestContext == null)
            return null;

        //if (controllerType == null)
        //{
        //    throw new HttpException(404, requestContext.HttpContext.Request.Path);
        //}

        return ObjectFactory.GetInstance(controllerType) as Controller;

    }

}







function LoadRequestDetails() {
    colRequestID = "Request ID"
    colReqDate = "Request Date";
    colRequestType = "Request Type";
    colRequestFor = "Requested for";
    colStatus = "Status"
    colPendingWith = "Pending with"
    colApprovedOn = "Approved on"
    colApprovedBy = "Approver Name"


    $("#listTemplateReport").jqGrid('GridUnload');
    jQuery("#listTemplateReport").jqGrid({
        datatype: 'json',
        postData: { LoadRequestType: $("#LoadRequestType").val(), LoadStatus: $("#LoadStatus").val(), CreatedTimeFirst: $("#datepicker").val(),
            CreatedTimeSecond: $("#enddatepicker").val(), Created_By: $("#Created_By").val(), RequestID: $("#RequestID").val()
        },
        url: $('#hdnLoadRequestDetails').val(),
        mtype: 'GET',
        colNames: [
                      colRequestID
                    , colReqDate
                    , colRequestType
                    , colRequestFor
                    , colStatus
                    , colPendingWith
                    , colApprovedOn
                    , colApprovedBy
                    ],
        colModel: [
                { name: 'RequestID', index: 'RequestID', width: '80px', align: 'center', sortable: true },
                { name: 'ReqDate', index: 'ReqDate', width: '80px', align: 'center', sortable: false },
                { name: 'RequestType', index: 'RequestType', width: '120px', align: 'left', sortable: false },
                { name: 'RequestFor', index: 'RequestFor', width: '130px', align: 'left', sortable: false },
                { name: 'Status', index: 'Status', width: '80px', align: 'left', sortable: false },
                { name: 'PendingWith', index: 'PendingWith', width: '100px', align: 'center', sortable: false },
                { name: 'ApprovedOn', index: 'ApprovedOn', width: '85px', align: 'center', sortable: false },
                { name: 'ApprovedBy', index: 'ApprovedBy', width: '175px', align: 'left', sortable: false }
                ],
        autowidth: true,
        pager: jQuery('#pager'),
        loadComplete: loadcomplete,
        rowNum: 10,
        sortname: 'RequestID',
        sortorder: "desc",
        altRows: true,
        viewrecords: true,
        height: "235",
        shrinkToFit: false
    });
   jQuery("#listTemplateReport").jqGrid('setGridParam').trigger("reloadGrid");


jquery("#listtemplatereport").jqgrid('navgrid', '#pager',
            {
                add: true, edit: true, view: true, del: true
            },
            {
                closeafteredit: true,
                closeafteradd: true,
                width: 400
            },
            {
                closeafteredit: true,
                closeafteradd: true,
                width: 400,
                serializeeditdata: function (data) { return $.param($.extend({}, data, { id: 0 })); }
            },
            {
        },
            {
                multiplesearch: true
            });

        jquery("#listtemplatereport").jqgrid('navbuttonadd', '#pager', { caption: "", buttonicon: "ui-icon-calculator", title: "choose columns",
            onclickbutton: function () {
                jquery("#listtemplatereport").jqgrid('columnchooser');
            }
        });

        jquery("#listtemplatereport").jqgrid('navbuttonadd', '#pager', {
            caption: "", buttonicon: "ui-icon-print", title: "excel export",
            onclickbutton: function () {
                            $.post("/viewreports/exporttoexcel", {}, function () {

                            });

推荐答案

#listTemplateReport ).jqGrid(' GridUnload');
jQuery( #listTemplateReport)。jqGrid({
datatype:< span class =code-string>' json'
postData:{LoadRequestType:
("#listTemplateReport").jqGrid('GridUnload'); jQuery("#listTemplateReport").jqGrid({ datatype: 'json', postData: { LoadRequestType:


#LoadRequestType)。val(),LoadStatus:
("#LoadRequestType").val(), LoadStatus:


#LoadStatus)。val(),CreatedTimeFirst:
("#LoadStatus").val(), CreatedTimeFirst:


这篇关于ASP.NET MVC3中的JQuery Grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆