This is a migrated thread and some comments may be shown as answers.

Overriding read.Action

1 Answer 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hery
Top achievements
Rank 1
Hery asked on 01 Jun 2016, 06:27 AM

Hi Telerik Team,

I have a grid using Ajax for data like so

.DataSource(dataSource =>
    dataSource.Ajax()
        .PageSize(20)
        .ServerOperation(true)
        .Read(read => read.Action("GetSerializedItems", "Inventory", new { storeId = Model.StoreID, fromSerialNo = Model.FromSerialNo , stockCode=Model.StockCode }))

And my Action in Controller 

[HttpPost]
public JsonResult GetSerializedItems([DataSourceRequest]DataSourceRequest request, List<string> fromSerialNo, string stockCode, string storeId)

And the Model for the request

public class RequestQueryInventoryStatus
{
    public string StoreID { get; set; }
    public List<string> FromSerialNo { get; set; }
    public string StockCode { get; set; }
    public string UserId { get; set; }
 
    public int? take { get; set; }
    public int? skip { get; set; }
    public int? page { get; set; }
    public int? pageSize { get; set; }
    public string sortField { get; set; }
    public string sortDir { get; set; }
}

However, the Action is unable to recognize the List of string and it takes the type System.Collections.Generic.List`1[System.String] as value instead. If I stringify the object Model.FromSerialNo, it will be too long to be in the query string, however the payload data of the post request has already been occupied by DataSourceRequest (with info like sort, page, etc.). Is there anyway to work around this issue?

Thanks,

Hery.

1 Answer, 1 is accepted

Sort by
0
Accepted
Ianko
Telerik team
answered on 03 Jun 2016, 08:51 AM
Hello Hery,

You can use the Data() method and assign a JS function that returns an object with the additional fields you want to load in the request data. 

Example:
...
datasource.Ajax().Read(read => read.Action("GetSerializedItems", "Inventory").Data("getData"))
...
<script>
    function getData() {
        return {
            storeId: @Model.StoreID,
            fromSerialNo: @Html.Raw(Json.Encode(Model.FromSerialNo)),
            stockCode: @Model.StockCode
        }
    }
</script>




Regards,
Ianko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Hery
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or