You can retrieve the UI metadata for a ViewModel from a MDriven Turnkey application when you are building a custom renderer or front end.
What ViewMeta provides
ViewMeta returns metadata for one view. A custom client can use this metadata to decide which controls to render, where to place them, and which labels to show.
The response describes UI-facing information, including:
- Control names and owners.
- Suggested control types, such as
grid,textbox, andcombobox. - Labels.
- Suggested layout information, including coordinates and row and column spans.
- Nested controls, for example the columns that belong to a grid.
It is limited metadata intended for rendering. It does not expose implementation details of the application.
Request metadata for a view
- Identify the runtime key (view name) of the ViewModel you want to render. For example, use
AllCarsfor a view namedAllCars. - Request the metadata endpoint on your application, replacing
<YourSite>and the view name:
http://<YourSite>/Turnkey/ViewMeta?view=AllCars
The endpoint returns XML. For example, a response can describe a grid and fields within it:
<root RowHeight="20" ColWidth="50">
<control type="grid" owner="AllCars" name="AllCar"
root="vCurrent_AllCars" label="All Car"
labelspan="1" colspan="3" rowspan="5" x="0" y="0"
nesting="AllCar">
<control type="textbox" name="AsString" label="As String" colspan="1" />
<control type="textbox" name="RegistrationNumber"
label="Registration Number" colspan="3" />
</control>
<control type="textbox" owner="TheCar" name="RegistrationNumber"
root="vCurrent_TheCar" label="Registration Number"
labelspan="1" colspan="1" rowspan="1" x="4" y="0" />
</root>
In this example, render AllCar as a grid at column x="0", row y="0", spanning three columns and five rows. Render AsString and RegistrationNumber as text boxes within that grid. Render the TheCar.RegistrationNumber field separately at column 4, row 0.
Interpret the layout hints
ViewMeta supplies suggested presentation details. Your renderer should use them consistently when it supports the corresponding control type.
| Metadata item | Meaning for a renderer | Example |
|---|---|---|
type
|
Suggested control type. | Render type="textbox" as a text input and type="grid" as a grid.
|
label
|
Text to show to the user. | Display Registration Number beside or above the field according to your layout.
|
x, y
|
Suggested column and row position for a top-level control. | Place a control with x="4" y="0" in column 4, row 0.
|
colspan, rowspan
|
Number of layout columns or rows occupied by a control. | A grid with colspan="3" rowspan="5" occupies three columns and five rows.
|
Nested control elements
|
Controls contained by another control. | Treat text boxes nested inside a grid as that grid's fields or columns. |
The root element can include layout defaults such as RowHeight and ColWidth. Use these values when your renderer implements the suggested grid-based layout.
Blazor client metadata
For a Blazor client, request the per-view client metadata endpoint:
http://<YourSite>/Turnkey/ViewMetaBlazorClient?view=NameOfViewModel
Replace NameOfViewModel with the name of the ViewModel to render. A Blazor client needs the metadata required to construct its UI on the client, so use this endpoint when implementing that client-side rendering scenario.
Design and security considerations
ViewMeta is intended to provide the information a renderer needs: names, suggested placement, suggested control types, and labels. Do not treat it as a substitute for runtime data or authorization. Your client must still use the normal Turnkey runtime flow to open a view and receive its data; the server remains responsible for access control.
ViewModel columns can have tagged values, and tagged values set on those columns appear in view metadata. Use that deliberately. For example, a custom renderer can use a tagged value as an instruction for its own presentation behavior, but do not put information in a tagged value that you do not want exposed to clients that retrieve this metadata.
Use ViewMeta in a custom renderer
Use the following division of responsibilities when you render a Turnkey view yourself:
- Discover available views and actions through the main-menu metadata.
- Open the selected view and obtain its runtime view identity.
- Retrieve runtime data from the server stream.
- Request ViewMeta for the view's runtime key.
- Build controls from the metadata and bind them to the runtime data.
- Send user actions through the appropriate Turnkey operation; do not rely on metadata as an authorization decision.
For the complete main-menu, open, server-stream, action, and target-group flow, see Documentation:Getting safeālimitedāmeta information from a Turnkey app. For an overview of building your own rendering engine, see Documentation:Rendering the MDriven Turnkey application yourself.
