LookupRecordContext

The LookupRecordContext component loads and provides editing access to the record referenced by a lookup field on the parent RecordContext. It inherits from BaseColumnEdit, so it binds to a column via the ColumnName parameter just like any other editor.

How It Works

When you place a LookupRecordContext inside a RecordContext and specify a ColumnName that maps to a lookup field, the component automatically reads the lookup value from the parent record, retrieves the referenced record from Dataverse, and exposes it as a nested RecordContext. Any editors placed inside the LookupRecordContext bind to the looked-up record's fields.

ColumnName

The ColumnName parameter must refer to a lookup column on the parent record. The component uses this to resolve the target table and record ID.

<RecordContext TableName="account" QueryParameterName="id">
    <LookupRecordContext ColumnName="primarycontactid">
        <ColumnEdit ColumnName="firstname" />
        <ColumnEdit ColumnName="lastname" />
        <ColumnEdit ColumnName="emailaddress1" />
    </LookupRecordContext>
</RecordContext>

Context Template

Like RecordContext, you can use the ContextTemplate parameter instead of ChildContent to access the looked-up TableRecord object directly in your markup.

<RecordContext TableName="account" QueryParameterName="id">
    <LookupRecordContext ColumnName="primarycontactid">
        <ContextTemplate>
            <h3>Primary Contact: @context["firstname"] @context["lastname"]</h3>
            <ColumnEdit ColumnName="emailaddress1" />
        </ContextTemplate>
    </LookupRecordContext>
</RecordContext>

Saving

Changes made to fields within a LookupRecordContext are saved as part of the parent MainContext save operation. The OnBeforeSave callback can be used to run custom logic or cancel the save.

<MainContext>
    <MenuBar>
        <SaveContextButton />
        <RefreshContextButton />
    </MenuBar>

    <RecordContext TableName="account" QueryParameterName="id">
        <ColumnEdit ColumnName="name" />

        <LookupRecordContext ColumnName="primarycontactid"
                              OnBeforeSave="OnBeforeSave">
            <ColumnEdit ColumnName="firstname" />
            <ColumnEdit ColumnName="lastname" />
        </LookupRecordContext>
    </RecordContext>
</MainContext>

@code {
    private async Task OnBeforeSave(CancelEventArgs eventArgs)
    {
        // Custom logic before saving the looked-up record
    }
}

Programmatic Access

The RecordContext property provides access to the inner RecordContext for programmatic operations such as refreshing or checking dirty state.

<LookupRecordContext @ref="_lookupContext" ColumnName="primarycontactid">
    <ColumnEdit ColumnName="firstname" />
</LookupRecordContext>

@code {
    private LookupRecordContext _lookupContext;

    private async Task RefreshContact()
    {
        await _lookupContext.RecordContext.RefreshAsync();
    }
}

Example

The following example shows an account form that displays the primary contact's details inline using a LookupRecordContext bound to the primarycontactid lookup field.

<MainContext>
    <MenuBar>
        <SaveContextButton />
        <RefreshContextButton />
    </MenuBar>

    <RecordContext TableName="account" QueryParameterName="accountId">
        <Section>
            <SectionColumn HeaderText="Account Info">
                <ColumnEdit ColumnName="name" />
                <LookupEdit ColumnName="primarycontactid" />
            </SectionColumn>
            <SectionColumn HeaderText="Primary Contact">
                <LookupRecordContext ColumnName="primarycontactid">
                    <ColumnEdit ColumnName="firstname" />
                    <ColumnEdit ColumnName="lastname" />
                    <ColumnEdit ColumnName="emailaddress1" />
                    <ImageEdit DisplayImage="true" ColumnName="ppp_profileimage" />
                </LookupRecordContext>
            </SectionColumn>
        </Section>
    </RecordContext>
</MainContext>

LookupRecordContext Class

Parameters

Name
Type
Default
Description
ChildContentRenderFragment?
Child content of the component
ColumnNamestring
Column logical name to bind the editor to from the table record.
ContextTemplateRenderFragment<TableRecord>
Render fragment that receives the loaded record for display or editing.
Descriptionstring?
Description to be displayed in the tooltip.
Disabledbool?
Should the editor be disabled.
DisplayLabelWhenAvailablebool
True
Specifies whether to display a lable if available.
DisplayTooltipWhenAvailablebool
True
Specifies whether to display a tooltip if available.
DisplayValidationErrorMessagebool
True
Should a validation error message be displayed when the component fails validation?
IsVisiblebool
True
Is the editor visible.
Labelstring?
Text to be displayed as a label for the editor.
ReadOnlybool?
Should the editor be read-only.
RecordContextRecordContext
Provides access to the inner for programmatic operations.
Requiredbool?
Should the value be required.
ValueLookupValue?
The current lookup value (reference) managed by this context.
Name: ChildContent
Type: RenderFragment?
Description: Child content of the component
Name: ColumnName
Type: string
Description: Column logical name to bind the editor to from the table record.
Name: ContextTemplate
Type: RenderFragment<TableRecord>
Description: Render fragment that receives the loaded record for display or editing.
Name: Description
Type: string?
Description: Description to be displayed in the tooltip.
Name: Disabled
Type: bool?
Description: Should the editor be disabled.
Name: DisplayLabelWhenAvailable
Type: bool
Default: True
Description: Specifies whether to display a lable if available.
Name: DisplayTooltipWhenAvailable
Type: bool
Default: True
Description: Specifies whether to display a tooltip if available.
Name: DisplayValidationErrorMessage
Type: bool
Default: True
Description: Should a validation error message be displayed when the component fails validation?
Name: IsVisible
Type: bool
Default: True
Description: Is the editor visible.
Name: Label
Type: string?
Description: Text to be displayed as a label for the editor.
Name: ReadOnly
Type: bool?
Description: Should the editor be read-only.
Name: RecordContext
Type: RecordContext
Description: Provides access to the inner for programmatic operations.
Name: Required
Type: bool?
Description: Should the value be required.
Name: Value
Type: LookupValue?
Description: The current lookup value (reference) managed by this context.

Events

Name
Type
Description
OnBeforeSaveEventCallback<CancelEventArgs>
Callback called before saving. Allows for cancelling the save operation.
ValueChangedEventCallback<ColumnValueBase>
Gets or sets a callback that updates the bound value.
Name: OnBeforeSave
Type: EventCallback<CancelEventArgs>
Description: Callback called before saving. Allows for cancelling the save operation.
Name: ValueChanged
Type: EventCallback<ColumnValueBase>
Description: Gets or sets a callback that updates the bound value.

Methods

Name
Parameters
Type
Description
GetValidationErrorsList<string>
Returns a collection of the current validation errors.
Name: GetValidationErrors
Type: List<string>
Description: Returns a collection of the current validation errors.