New to Telerik UI for ASP.NET Core? Start a free 30-day trial
How to Pass Additional Data With the DataSourceResult Back to the View
Updated over 6 months ago
Environment
| Product | Telerik UI for ASP.NET Core |
Description
How can I pass additional data through the DataSourceResult from the Controller back to the View?
Solution
The desired result can be achieved by following the steps below:
- Store the output of the
ToDataSourceResultmethod in a variable. - Return a custom JSON result with the same field names and add the additional fields.
- Handle the
RequestEndevent of the DataSource to retrieve the additional data when the response of the request is received.
C#
var resultFinal = result.ToDataSourceResult(request);
return Json(new
{
Data = resultFinal.Data,
Total = resultFinal.Total,
AggregateResults = resultFinal.AggregateResults,
Errors = resultFinal.Errors,
myAdditionalParam = "additional data" // Add the desired parameter.
});