NHK
NHK

Reputation: 107

How to pass object as parameter to kendo grid read method

I have kendo grid as follow.

 @(Html.Kendo().Grid<ManualInputDetail>()
          .Name("gManualInputDetail")
          .Columns(columns =>
          {
              columns.Bound(c => c.Id).Hidden(true);
              columns.Bound(c => c.Month).Title("Month");
              columns.Bound(c => c.Value).Title("Value");
          })
          .Editable(editable => editable.Mode(GridEditMode.InLine))
          .Pageable()
          .Navigatable()
          .Selectable(selectable =>
          {
              selectable.Mode(GridSelectionMode.Single);
              selectable.Type(GridSelectionType.Row);
          })
          .Sortable(sortable =>
          {
              sortable.SortMode(GridSortMode.MultipleColumn);
          })
          .DataSource(dataSource => dataSource
              .WebApi()
              .Model(model => model.Id(p => p.Id))
              .PageSize(12)
              .Read(read => read.Url(Url.HttpRouteUrl("ActionApi", new { controller = "ManualInputDetails", action = "GetManualInputDetails" })).Data("getFilterData"))
          )
          .Pageable(p => p.Refresh(true))
          )

using getFilterData function I want to pass object parameter to read method. getFilterData function as follow

function getFilterData() {
    var header= {
        SectorId: 1,
        BrandId: 2,
        LocationId: 1,
        DataElementId:2
    }
    return {
        header: header
    };
}

GetManualInputDataElements method as follow

[ActionName("GetManualInputDetails")]
    public DataSourceResult GetManualInputDetails([System.Web.Http.ModelBinding.ModelBinder(typeof(WebApiDataSourceRequestModelBinder))] DataSourceRequest request,ManualInputHeader header)
    {
        var model = new DataElementMgt().GetAll(header).Select(x => new DataElement()
        {
            Id = x.Id,
            DataElementTypeId = x.DataElementTypeId,
            Name = x.Name,
            Descriptionn = x.Descriptionn
        }).ToList().ToDataSourceResult(request);
        return model;
    }

In here header value always gives as null. What is the reason for that. Is any thing wrong? Please help..

Upvotes: 0

Views: 967

Answers (1)

AirWolf
AirWolf

Reputation: 597

change the getFilterData method to this

function getFilterData() {
    var _header= {
        SectorId: 1,
        BrandId: 2,
        LocationId: 1,
        DataElementId:2
    }
    return {
        header: _header
    };
}

and it should work. dont use the same name for what you return and declare.

Upvotes: 1

Related Questions