DataSourceLoadOptionsExtensions.ConvertToHttpContent(DataSourceLoadOptionsBase) Method
Generates an HTTP request content based on the specified data loading options.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
public static HttpContent ConvertToHttpContent(
this DataSourceLoadOptionsBase options
)
Parameters
Name | Type | Description |
---|---|---|
options | DevExtreme.AspNet.Data.DataSourceLoadOptionsBase | A DataSourceLoadOptionsBase object that should be converted to HTTP content. |
Returns
Type | Description |
---|---|
HttpContent | The HTTP request content. |
Remarks
The ConvertToHttpContent
extension method helps you bind DevExpress Blazor components to a Web API service. The following table lists supported components.
Component | Property |
---|---|
Assign the data source type to the component’s T
parameter and specify the CustomData
property’s delegate that asynchronously loads data from a Web API service. This delegate accepts a DataSourceLoadOptionsBase object as a parameter. Call the ConvertToHttpContent
extension method to generate an HTTP request content based on the accepted data loading options.
The following example binds the Data Grid to a Web API service.
@using DevExtreme.AspNet.Data
@using DevExtreme.AspNet.Data.ResponseModel
@using System.Threading
@using System.Threading.Tasks
@using System.Net.Http
@using System.Text.Json
<DxDataGrid T="@WebApiDataSource" CustomData="@LoadCustomData">
...
</DxDataGrid>
@code {
[Inject] protected HttpClient Client { get; set; }
public class WebApiDataSource {
// Declare data source fields here.
}
protected async Task<LoadResult> LoadCustomData(DataSourceLoadOptionsBase options, CancellationToken cancellationToken) {
using var response = await Client.PostAsync("https://MyWebApiService", options.ConvertToHttpContent(), cancellationToken);
response.EnsureSuccessStatusCode();
using var responseStream = await response.Content.ReadAsStreamAsync();
return await JsonSerializer.DeserializeAsync<LoadResult>(responseStream, cancellationToken: cancellationToken);
}
}