Table of Contents

Class ModelHandler<T, TKey>

Namespace
Htmx.Components.Models
Assembly
Htmx.Components.dll

Strongly-typed model handler that provides CRUD operations and UI generation for a specific model type. Coordinates between data access, business logic, and UI presentation.

public class ModelHandler<T, TKey> : ModelHandler where T : class

Type Parameters

T

The model type being handled

TKey

The type of the model's primary key

Inheritance
ModelHandler<T, TKey>
Inherited Members
Extension Methods

Properties

KeySelector

Gets or sets the key selector expression used to identify the primary key of the model. This expression is used for entity identification, filtering, and CRUD operations.

public Expression<Func<T, TKey>> KeySelector { get; set; }

Property Value

Expression<Func<T, TKey>>

An expression that selects the primary key property or properties from the model type. The expression is compiled for performance when accessing key values.

Methods

BuildInputModel(string)

Builds an input model for the specified input name. Input models are used for form field generation and data binding.

public Task<IInputModel> BuildInputModel(string name)

Parameters

name string

The name of the input model to build.

Returns

Task<IInputModel>

A task that represents the asynchronous operation. The task result contains the built input model.

Exceptions

ArgumentException

Thrown when no input model builder is found for the specified name.

BuildTableModelAndFetchPageAsync(TableState?)

Builds a table model and fetches the requested page of data based on the table state. If no table state is provided, creates a new default table state and stores it in the page state.

public Task<TableModel<T, TKey>> BuildTableModelAndFetchPageAsync(TableState? tableState = null)

Parameters

tableState TableState

The current table state containing pagination, sorting, and filtering information. If null, a new default table state will be created and stored.

Returns

Task<TableModel<T, TKey>>

A task that represents the asynchronous operation. The task result contains a table model populated with the requested page of data.

Exceptions

InvalidOperationException

Thrown when the GetQueryable delegate is not configured.

BuildTableModelAsync()

Builds a table model for displaying the entities in a tabular format. Applies the configured table model settings without fetching data.

public Task<TableModel<T, TKey>> BuildTableModelAsync()

Returns

Task<TableModel<T, TKey>>

A task that represents the asynchronous operation. The task result contains a configured table model ready for data population.

GetKeyPredicate(TKey)

Creates a predicate expression for the key selector. This is used to filter a collection to a single item based on the key. The key can be a simple value type, a string, or a composite type (e.g., a tuple or a class).

public Expression<Func<T, bool>> GetKeyPredicate(TKey key)

Parameters

key TKey

Returns

Expression<Func<T, bool>>

Exceptions

NotSupportedException