将JqGrid数据源传递到MVC控制器 [英] Passing JqGrid data source to MVC controller

查看:281
本文介绍了将JqGrid数据源传递到MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了很多关于此的文章,但仍然无法弄清楚如何将数据源发送到控制器(而不是将应用的过滤器发送到网格).我不想在后端再次查询存储库,而是希望在MVC Controller中接收jQGrid数据源.

我需要以某种方式在控制器中将数据源作为集合来获取,以便可以将其导出到CSV文件.

我在jqgrid中定义了以下按钮,下一个代码块是jQgrid I'm设置的属性.我不知道如何将jQgrid的当前数据源(已应用过滤器)传递给MVC控制器.

I have looked up a lot of posts regarding this but still cant figure out how to send the data source to controller (instead of applied filters to the grid). Instead of querying the repository again in the back end I would like to receive the jQGrid data source in the MVC Controller.

I need to somehow get the datasource as a collection in the controller so I can export it to CSV file.

I have defined the following button in jqgrid and next block of code are the properties of the jQgrid I''m setting. I don''t know how can I pass the jQgrid''s current datasource(filters applied) to the MVC controller.

$("#btnExportCsv").click(function () {
            $.blockUI({ css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                color: '#fff'
            }, message: '<h1>Exporting to CSV</h1><p><img src="/cms/themes/cm-blue/img/busy.gif" /></p>'
            });

            generating = true;

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: exportCsvUrl,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.jGrowl(XMLHttpRequest.responseText, { header: 'Error exporting csv' });
                    generating = false;
                },
                complete: function () {
                    $.unblockUI();
                },
                success: function () {
                    growl("Export completed successfully", "Export to Csv");
                }
            });

        });




-----------------------------------




-----------------------------------

jQGrid params:

$("#myGrid").jqGrid({
        colNames: [
    .
    .
    .
        ],
        colModel: [...]
        mtype: 'POST',
        datatype: 'json',
        pager: '#crPager',
        page: defaultGridParams.Page,
        sortname: defaultGridParams.SortName,
        sortorder: defaultGridParams.SortOrder,
        rowNum: 10,
        rowList: [10, 20, 50, 100],
        url: Controllers/control,
        height: 'auto',
        loadui: 'block',
        width: 1200,
        caption: sGridCaption,
        hidegrid: false,
        viewrecords: true,
        ShrinkToFit: false,


.
.
.


.
.
.

推荐答案

(" ).click(函数(){
("#btnExportCsv").click(function () {


.blockUI({css:{ 边框:' 没有', 填充:' 15px', backgroundColor:' #000'' -webkit-border-radius':' 10px'' -moz-border-radius':' span> 10px', 颜色:' #fff' },消息:' < h1>导出为CSV</h1>< p>< img src ="/cms/themes/cm-blue/img/busy.gif"/></p>' }); generation = true ;
.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', color: '#fff' }, message: '<h1>Exporting to CSV</h1><p><img src="/cms/themes/cm-blue/img/busy.gif" /></p>' }); generating = true;


.ajax({ 类型:' POST', dataType:' json', 网址:exportCsvUrl, 错误:函数(XMLHttpRequest,textStatus,errorThrown){
.ajax({ type: 'POST', dataType: 'json', url: exportCsvUrl, error: function (XMLHttpRequest, textStatus, errorThrown) {


这篇关于将JqGrid数据源传递到MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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