Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataSourceLoadOptionsExtensions.ConvertToHttpContent(DataSourceLoadOptionsBase) Method

Generates an HTTP request content based on the specified data loading options.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
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

DxComboBox<TData, TValue>

CustomData

DxListBox<TData, TValue>

CustomData

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