blazor-devexpress-dot-blazor-dot-datasourceloadoptionsextensions-dot-converttohttpcontent-x28-devextreme-dot-aspnet-dot-data-dot-datasourceloadoptionsbase-x29.md
Generates an HTTP request content based on the specified data loading options.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public static HttpContent ConvertToHttpContent(
this DataSourceLoadOptionsBase options
)
| Name | Type | Description |
|---|---|---|
| options | DevExtreme.AspNet.Data.DataSourceLoadOptionsBase |
A DataSourceLoadOptionsBase object that should be converted to HTTP content.
|
| Type | Description |
|---|---|
| HttpContent |
The HTTP request content.
|
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);
}
}
See Also
DataSourceLoadOptionsExtensions Class