How to use HTTP POST request in ASP.NET MVC igGrid wrapper?

253 views Asked by At

It seems quite simple to use HTTP POST method in igGrid using ajax post call by specifying requestType attribute. But, I am not able to find any method to specify the requestType in ASP.NET MVC wrapper for igGrid ( Infragistics 16.2 ).

@(Html.Infragistics()
        .Grid(Model)
        .ID("transactionGrid")
        .PrimaryKey("ID")
        .Height("550px")
        .Width("100%")
        .AutoGenerateColumns(false)
        .AutoGenerateLayouts(false)
        .Columns(column =>
        {
            column.For(x => x.ID).HeaderText("Broker");
            column.For(x => x.Category).HeaderText("Category");
            //column.For(x => x.BrokerName).HeaderText("Broker");
            column.For(x => x.ParAmount).HeaderText("Par").Format("N2");
            column.For(x => x.CommissionAmount).HeaderText("Commission").Format("N2");
        })
        .Features(features =>
        {
            features.Sorting().Type(OpType.Local);
            features.Filtering().Type(OpType.Local);
            features.Summaries()
                .Type(OpType.Local).CalculateRenderMode(SummaryCalculateRenderMode.OnSelect)
                .ColumnSettings(cs =>
                {
                    cs.ColumnSetting().ColumnKey("CommissionAmount").SummaryOperands(so =>
                    {
                        so.SummaryOperand().Type(SummaryFunction.Sum).Active(true);
                    });
                    cs.ColumnSetting().ColumnKey("ParAmount").SummaryOperands(so =>
                    {
                        so.SummaryOperand().Type(SummaryFunction.Sum).Active(true);
                    });
                    cs.ColumnSetting().ColumnKey("Category").AllowSummaries(false);
                    cs.ColumnSetting().ColumnKey("ID").AllowSummaries(false);
                });
        })
        .DataSourceUrl(Url.Action("GetTransactions"))
        .DataBind()
        .Render()
    )
2

There are 2 answers

1
Stamen Stoychev On

You can still set it through the grid prototype with:

$.ui.igGrid.prototype.requestType = "POST"

added somewhere before the grid initialization code.

The reason it is not exposed is that the automated remote operations such as Sorting/Filtering/Paging etc. only work with parameters encoded in the URL which assumes a GET request. If you handle the remote operations yourself, that is you are not decorating your controller methods with GridDataSourceActionAttribute, there is no reason you can't change the request type through the aforementioned prototype change and read and process the query from the request body.

Hope this helps!

0
Yousaf Khan On

I found the answer: As the Grid ASP.NET MVC Wrappers main use case is to be used with the server-side handling of the remote grid features the "requestType" option is not exposed in the wrapper, because the server-side features handling (GridModel.GetData and GridDataSourceAction) is only working with HTTP GET method.

Exposing requestType in the MVC Wrapper is something that they are looking forward to implement in a future version of Ignite UI for JavaScript, but Ignite UI 16.2 is out of support, so it won't get into it.