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;
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 () {
});