# Menu Data Binding Basics

This article explains the different ways to provide data to a Menu component, the properties related to data binding and their results.

For details on Value Binding and Data Binding, and the differences between them, see the [Data Binding vs Value Binding](https://www.telerik.com/blazor-ui/documentation/common-features/data-binding/overview#data-binding-vs-value-binding) section.

First, review:

* The available (bindable) [features of a menu item](https://www.telerik.com/blazor-ui/documentation/components/menu/data-binding/overview#menu-item-features).
* How to match fields in the model with the menu item [data bindings](https://www.telerik.com/blazor-ui/documentation/components/menu/data-binding/overview#data-bindings).

There are two modes of providing data to a menu, and both use the items' features. Once you are familiar with this article, choose the data binding mode you want to use:

* [Hierarchical data](https://www.telerik.com/blazor-ui/documentation/components/menu/data-binding/hierarchical-data) - separate collections of items and their child items.
* [Flat data](https://www.telerik.com/blazor-ui/documentation/components/menu/data-binding/flat-data) - a single collection of items with defined parent-child relationships.

## Menu Item Features

The menu items provide the following features that you control through the corresponding fields in their data binding:

* `Id` - a unique identifier for the item. Required for binding to flat data.

* `ParentId` - identifies the parent to whom the item belongs. Required only when binding to flat data. All items with the same `ParentId` will be rendered at the same level. For a root level item, this must be `null`.

* `HasChildren` - can hide child items. The menu will fetch its children from the data source based on the `Id`-`ParentId` relationships (for flat data) or on the presence of the `Items` collection (for hierarchical data). If you set `HasChildren` to `false`, child items will not be rendered even if they are present in the data. If there are no child items in the data, an expand icon will not be rendered regardless of its value.

* `Items` - the collection of child items that will be rendered under the current item. Required only when binding to hierarchical data.

* `Text` - the text that will be shown on the item.

* `Icon` - The [Telerik Font or SVG icon](https://www.telerik.com/blazor-ui/documentation/common-features/icons) that will be rendered in the item. Read more in the [Icons article](https://www.telerik.com/blazor-ui/documentation/components/breadcrumb/icons).

* `IconVariant` - the [SVG icon variant](https://www.telerik.com/blazor-ui/documentation/common-features/icons#use-svg-icon-variants) to use for the item icon.

* `Url` - the view the item will navigate to by generating a link.

* `Separator` - when set to `true`, the item will be just a line that makes a distinction between its neighbors clearly visible. Thus, you can place logically grouped items between two separators to distinguish them. A separator item does not render text, icons, children or a navigable link.

* `Disabled` - You can disable items by setting this field to `true`. Such items will keep rendering but will not be clickable.

* `Description` - an optional secondary line of text below the item text. The Menu renders the description only when you set the `DescriptionField` parameter and the field value is a non-empty `string`. If the field is missing or is not a `string`, the Menu does not render a description.

* `GroupHeader` - when set to `true`, the child item renders as a non-interactive group header in its popup. The group header organizes the items that follow it. The root items of the Menu ignore this field. [Read more about item grouping...](https://www.telerik.com/blazor-ui/documentation/components/menu/item-grouping)

## Data Bindings

The properties of a menu item match directly to a field of the model the menu is bound to. You provide that relationship by providing the name of the field from which the corresponding information is present. To do this, use the properties in the main `TelerikMenu` tag:

* IdField => Id
* ParentIdField => ParentId
* TextField => Text
* IconField => Icon
* IconVariantField => IconVariant
* UrlField => Url
* HasChildrenField => HasChildren
* ItemsField => Items
* DisabledField => Disabled
* SeparatorField => Separator
* DescriptionField => no default value. Set this parameter to display item descriptions.
* GroupHeaderField => GroupHeader

> tip There are default values for the field names. If your model names match the defaults, you don't have to define them in the bindings settings. The only exception is `DescriptionField`, which you must set explicitly to display descriptions.

> note If your model has a `GroupHeader` property with a `true` value, the Menu renders the respective child items as group headers, even if you don't set `GroupHeaderField`.

If your model field names match any of the default names, the component will try to use them. For example, a field called `Icon` will try to produce a Telerik icon out of those values and that may not be what you want. If you want to override such behaviors, you can set `IconField="someNonExistingField"`. You can read more about this [here](https://www.telerik.com/blazor-ui/documentation/knowledge-base/common-custom-font-icons-fail). This also applies to other fields too. Another example would be a field called `Url` - in case you want to perform navigation yourself through templates, you may want to set `UrlField="someFakeField"` so that the component does not navigate on its own.

> caption Default field names for menu item bindings. If you use these, you don't have to specify them in the `TelerikMenu` tag explicitly.

```RAZOR
public class MenuItem
{
	public int Id { get; set; }
	public string Text { get; set; }
	public int? ParentId { get; set; }
	public bool HasChildren { get; set; }
	public ISvgIcon Icon { get; set; }
	public string Url { get; set; }
	public bool Disabled { get; set; }
	public bool Separator { get; set; }
	public bool GroupHeader { get; set; }
}
```

> caption Data bind the menu to a model with custom field names

<demo metaUrl="client/menu/overview/example-3/" height="320"></demo>

> caption The result from the snippet above

![Menu data binding example with custom field names](https://www.telerik.com/blazor-ui/documentation/assets/d23c0cc6db4f31e0d36060819691da0e/menu-databinding-example.png)

> caption Bind the item descriptions and group headers to custom fields

<demo metaUrl="client/menu/data-binding/example-1/" height="360"></demo>

## See Also

* [Binding to Flat Data](https://www.telerik.com/blazor-ui/documentation/components/menu/data-binding/flat-data)
* [Binding to Hierarchical Data](https://www.telerik.com/blazor-ui/documentation/components/menu/data-binding/hierarchical-data)
* [Live Demo: Menu Flat Data](https://demos.telerik.com/blazor-ui/menu/flat-data)
* [Live Demo: Menu Hierarchical Data](https://demos.telerik.com/blazor-ui/menu/hierarchical-data)
