New to Telerik UI for ASP.NET MVC? Start a free 30-day trial

Defines the fluent interface for configuring the Menu component.

Definition

Constructors

Initializes a new instance of the MenuBuilder class.

C#
public MenuBuilder(Menu component)
Parameters:componentMenu

The component.

Methods

Sets the menu animation options.

C#
public MenuBuilder Animation(Action<PopupAnimationBuilder> animationAction)
Parameters:animationActionAction<PopupAnimationBuilder>

The animation settings.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Animation(a =&gt; a.Open(o =&gt; o.Expand(ExpandDirection.Vertical)))
)

Disables the menu animation.

C#
public MenuBuilder Animation(bool enable)
Parameters:enablebool

Boolean parameter.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Animation(false)
)

Binds the menu to a list of objects. The menu will create a hierarchy of items using the specified mappings.

C#
public MenuBuilder BindTo(IEnumerable dataSource, Action<NavigationBindingFactory<MenuItem>> factoryAction)
Parameters:dataSourceIEnumerable

The data source.

factoryActionAction<NavigationBindingFactory<MenuItem>>

The action which will configure the mappings

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.BindTo(Model, mapping =&gt; mapping
.For&lt;Customer&gt;(binding =&gt; binding
.Children(c =&gt; c.Orders) // The "child" items will be bound to the "Orders" property
.ItemDataBound((item, c) =&gt; item.Text = c.ContactName) // Map "Customer" properties to MenuItem properties
)
.For&lt;Order&lt;(binding =&gt; binding
.Children(o =&gt; null) // "Orders" do not have child objects so return "null"
.ItemDataBound((item, o) =&gt; item.Text = o.OrderID.ToString()) // Map "Order" properties to MenuItem properties
)
)
)

Binds the menu to a list of items. Use if the menu items are being sent from the controller. To bind the Menu declaratively, use the Items(Action<MenuItemFactory>) method.

C#
public MenuBuilder BindTo(IEnumerable<MenuItem> items)
Parameters:itemsIEnumerable<MenuItem>

The list of items

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("TreeView")
.BindTo(model)
)

Binds the menu to a sitemap

C#
public MenuBuilder BindTo(string viewDataKey, Action<MenuItem, SiteMapNode> siteMapAction)
Parameters:viewDataKeystring

The view data key.

siteMapActionAction<MenuItem, SiteMapNode>

The action to configure the item.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.BindTo("examples", (item, siteMapNode) =&gt;
{
})
)

Binds the menu to a sitemap.

C#
public MenuBuilder BindTo(string viewDataKey)
Parameters:viewDataKeystring

The view data key.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.BindTo("examples")
)

Binds the menu to a list of objects. The menu will be "flat" which means a menu item will be created for every item in the data source.

C#
public MenuBuilder BindTo<T>(IEnumerable<T> dataSource, Action<MenuItem, T> itemDataBound)
Parameters:dataSourceIEnumerable<T>

The data source.

itemDataBoundAction<MenuItem, T>

The action executed for every data bound item.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.BindTo(new []{"First", "Second"}, (item, value) =&gt;
{
item.Text = value;
})
)

Specifies that sub menus should close after item selection (provided they won't navigate).

C#
public MenuBuilder CloseOnClick(bool value)
Parameters:valueboolReturns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.CloseOnClick(false)
)

Sets the field of the data item that provides the content of the menu items.

C#
public MenuBuilder DataContentField(string value)
Parameters:valuestring

The value for DataContentField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataContentField("Value")
)

Sets the field of the data item that provides the icon class of the menu items.

C#
public MenuBuilder DataIconClassField(string value)
Parameters:valuestring

The value for DataIconClassField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataIconClassField("Value")
)

Sets the field of the data item that provides the icon name of the menu items.

C#
public MenuBuilder DataIconField(string value)
Parameters:valuestring

The value for DataIconField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataIconField("Value")
)

Sets the field of the data item that provides the image url of the menu items.

C#
public MenuBuilder DataImageUrlField(string value)
Parameters:valuestring

The value for DataImageUrlField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataImageUrlField("Value")
)

Configure the DataSource of the component

C#
public MenuBuilder DataSource(Action<HierarchicalDataSourceBuilder<object>> configurator)
Parameters:configuratorAction<HierarchicalDataSourceBuilder<object>>

The action that configures the DataSource.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataSource(dataSource =&gt; dataSource
.Read(read =&gt; read
.Action("Employees", "PanelBar")
)
)
)

Sets the DataSource ID of the component

C#
public MenuBuilder DataSource(string dataSourceId)
Parameters:dataSourceIdstring

Configures the DataSource ID.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataSource("dataSourceId")
)

Sets the field of the data item that provides the sprite css class of the menu items.

C#
public MenuBuilder DataSpriteCssClassField(string value)
Parameters:valuestring

The value for DataSpriteCssClassField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataSpriteCssClassField("Value")
)

Sets the field of the data item that provides the text of the menu items.

C#
public MenuBuilder DataTextField(string value)
Parameters:valuestring

The value for DataTextField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataTextField("Value")
)

Sets the field of the data item that provides the url of the menu items.

C#
public MenuBuilder DataUrlField(string value)
Parameters:valuestring

The value for DataUrlField

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.DataUrlField("Value")
)

Specifies Menu opening direction.

C#
public MenuBuilder Direction(MenuDirection value)
Parameters:valueMenuDirection

The desired direction.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Direction(MenuDirection.Left)
)

Specifies Menu opening direction.

C#
public MenuBuilder Direction(string value)
Parameters:valuestring

The desired direction.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Direction("top")
)

Configures the client-side events.

C#
public MenuBuilder Events(Action<MenuEventBuilder> clientEventsAction)
Parameters:clientEventsActionAction<MenuEventBuilder>

The client events action.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Events(events =&gt;
events.Open("onOpen").OnClose("onClose")
)
)

Select item depending on the current URL.

C#
public MenuBuilder HighlightPath(bool value)
Parameters:valuebool

If true the item will be highlighted.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.HighlightPath(true)
)

Specifies the delay in ms before the menu is opened/closed - used to avoid accidental closure on leaving.

C#
public MenuBuilder HoverDelay(int value)
Parameters:valueintReturns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.HoverDelay(300)
)

Specifies the position of the icon in the Menu items using the text content as a reference.

C#
public MenuBuilder IconPosition(IconPosition value)
Parameters:valueIconPosition

The value for IconPosition

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.IconPosition(IconPosition.After)
)

Callback for each item.

C#
public MenuBuilder ItemAction(Action<MenuItem> action)
Parameters:actionAction<MenuItem>

Action, which will be executed for each item.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.ItemAction(item =&gt;
{
item
.Text(...)
.HtmlAttributes(...);
})
)

Defines the items in the menu

C#
public MenuBuilder Items(Action<MenuItemFactory> addAction)
Parameters:addActionAction<MenuItemFactory>

The add action.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Items(items =&gt;
{
items.Add().Text("First Item");
items.Add().Text("Second Item");
})
)

If RootMenuItems setting is enabled - all root menus will be opened on click. Respectively, if SubMenuItems is enabled - all sub menus will be opened on click.

C#
public MenuBuilder OpenOnClick(Action<MenuOpenOnClickBuilder> openOnClickAction)
Parameters:openOnClickActionAction<MenuOpenOnClickBuilder>Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.OpenOnClick(o =&gt; o.RootMenuItems(true).SubMenuItems(true))
)

Enables or disables the "open-on-click" feature.

C#
public MenuBuilder OpenOnClick(bool value)
Parameters:valueboolReturns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.OpenOnClick(true)
)

Sets the menu orientation.

C#
public MenuBuilder Orientation(MenuOrientation value)
Parameters:valueMenuOrientation

The desired orientation.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Orientation(MenuOrientation.Vertical)
)

Sets the menu popup collision detection.

C#
public MenuBuilder PopupCollision(Action<PopupCollisionBuilder> popupCollisionAction)
Parameters:popupCollisionActionAction<PopupCollisionBuilder>

The collision action. Can be "fit", "flip" or "fit flip".

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.PopupCollision(c =&gt; c.Collision("flip"))
)

Disables the menu popup collision detection.

C#
public MenuBuilder PopupCollision(bool enable)
Parameters:enablebool

Boolean parameter.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.PopupCollision(false)
)

If enabled, the Menu will display buttons that will scroll the menu items, when they cannot fit the Menu width or menu popups height. By default scrolling is disabled.

C#
public MenuBuilder Scrollable(Action<MenuScrollableBuilder> scrollableAction)
Parameters:scrollableActionAction<MenuScrollableBuilder>Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Scrollable(s =&gt; s.Distance(300))
)

If enabled, the Menu will display buttons that will scroll the menu items, when they cannot fit the Menu width or menu popups height. By default scrolling is disabled.

C#
public MenuBuilder Scrollable(bool enabled)
Parameters:enabledbool

Boolean flag.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.Scrollable(true)
)

Defines the security trimming functionality of the component

C#
public MenuBuilder SecurityTrimming(Action<SecurityTrimmingBuilder> securityTrimmingAction)
Parameters:securityTrimmingActionAction<SecurityTrimmingBuilder>

The securityTrimming action.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.SecurityTrimming(builder =&gt;
{
builder.Enabled(true).HideParent(true);
})
)

Enable/disable security trimming functionality of the component.

C#
public MenuBuilder SecurityTrimming(bool value)
Parameters:valuebool

If true security trimming is enabled.

Returns:

MenuBuilder

Example:
C#
@( Html.Kendo().Menu()
.Name("Menu")
.SecurityTrimming(false)
)