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

Defines the fluent interface for configuring the ContextMenu component.

Definition

Constructors

Initializes a new instance of the ContextMenuBuilder class.

C#
public ContextMenuBuilder(ContextMenu component)
Parameters:componentContextMenu

The component.

Methods

Specifies that context menu would align to its anchor (target or filter).

C#
public ContextMenuBuilder AlignToAnchor(bool value)
Parameters:valueboolReturns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.AlignToAnchor(false)
)

Sets the Animation options.

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

The animation settings.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.Animation(a =&gt; a.Open(o =&gt; o.Expand(ExpandDirection.Vertical)))
.Items(items =&gt;
{
items.Add().Text("First Item");
items.Add().Text("Second Item");
})
)

Toggles the ContextMenu Animation.

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

Boolean parameter.

Returns:

ContextMenuBuilder

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

Which DOM element the ContextMenu will be appended to. The element needs to be relatively positioned.

C#
public ContextMenuBuilder AppendTo(string value)
Parameters:valuestring

The value for AppendTo

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.AppendTo("#container")
)

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

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

The data source.

factoryActionAction<NavigationBindingFactory<ContextMenuItem>>

The action which will configure the mappings

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.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 ContextMenuItem 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 ContextMenuItem properties
)
)
)

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

C#
public ContextMenuBuilder BindTo(IEnumerable<ContextMenuItem> items)
Parameters:itemsIEnumerable<ContextMenuItem>

The list of items

Returns:

ContextMenuBuilder

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

Binds the menu to a sitemap

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

The view data key.

siteMapActionAction<ContextMenuItem, SiteMapNode>

The action to configure the item.

Returns:

ContextMenuBuilder

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

Binds the menu to a sitemap.

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

The view data key.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.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 ContextMenuBuilder BindTo<T>(IEnumerable<T> dataSource, Action<ContextMenuItem, T> itemDataBound)
Parameters:dataSourceIEnumerable<T>

The data source.

itemDataBoundAction<ContextMenuItem, T>

The action executed for every data bound item.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.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 ContextMenuBuilder CloseOnClick(bool value)
Parameters:valueboolReturns:

ContextMenuBuilder

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

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

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

The value for DataContentField

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.DataContentField("ContentField")
)

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

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

The value for DataImageUrlField

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.DataImageUrlField("ImageUrlField")
)

Configure the DataSource of the component

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

The action that configures the DataSource.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.DataSource(dataSource =&gt; dataSource
.Read(read =&gt; read
.Action("GetData", "Home")
)
)
)

Sets the DataSource ID of the component

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

Configures the DataSource ID.

Returns:

ContextMenuBuilder

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

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

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

The value for DataSpriteCssClassField

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.DataSpriteCssClassField("CSSField")
)

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

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

The value for DataTextField

Returns:

ContextMenuBuilder

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

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

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

The value for DataUrlField

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.DataUrlField("UrlField")
)

Specifies ContextMenu opening direction.

C#
public ContextMenuBuilder Direction(ContextMenuDirection value)
Parameters:valueContextMenuDirection

The desired direction.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.Direction(ContextMenuDirection.Left)
)

Specifies ContextMenu opening direction.

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

The desired direction.

Returns:

ContextMenuBuilder

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

Configures the client-side events.

C#
public ContextMenuBuilder Events(Action<ContextMenuEventBuilder> clientEventsAction)
Parameters:clientEventsActionAction<ContextMenuEventBuilder>

The client events action.

Returns:

ContextMenuBuilder

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

Specifies the filter selector. The ContextMenu will be shown only for the elements that match the selector.

C#
public ContextMenuBuilder Filter(string value)
Parameters:valuestring

The desired filter.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.Target("#target")
.Filter(".item")
)

Select item depending on the current URL.

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

If true the item will be highlighted.

Returns:

ContextMenuBuilder

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

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

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

ContextMenuBuilder

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

Callback for each item.

C#
public ContextMenuBuilder ItemAction(Action<ContextMenuItem> action)
Parameters:actionAction<ContextMenuItem>

Action, which will be executed for each item.

Returns:

ContextMenuBuilder

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

Defines the items in the menu.

C#
public ContextMenuBuilder Items(Action<ContextMenuItemFactory> addAction)
Parameters:addActionAction<ContextMenuItemFactory>

The add action.

Returns:

ContextMenuBuilder

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

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

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

ContextMenuBuilder

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

Sets the menu orientation.

C#
public ContextMenuBuilder Orientation(ContextMenuOrientation value)
Parameters:valueContextMenuOrientation

The desired orientation.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.Orientation(ContextMenuOrientation.Vertical)
)

If enabled, the ContextMenu will display buttons that will scroll the ContextMenu items, when they cannot fit the viewport height. By default scrolling is disabled.

C#
public ContextMenuBuilder Scrollable(Action<ContextMenuScrollableBuilder> scrollableAction)
Parameters:scrollableActionAction<ContextMenuScrollableBuilder>Returns:

ContextMenuBuilder

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

If enabled, the ContextMenu will display buttons that will scroll the ContextMenu items, when they cannot fit the viewport height. By default scrolling is disabled.

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

Boolean flag.

Returns:

ContextMenuBuilder

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

Defines the security trimming functionality of the component

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

The securityTrimming action.

Returns:

ContextMenuBuilder

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

Enable/disable security trimming functionality of the component.

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

If true security trimming is enabled.

Returns:

ContextMenuBuilder

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

Specifies ContextMenu triggering event.

C#
public ContextMenuBuilder ShowOn(string value)
Parameters:valuestring

The desired event.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.ShowOn("click")
)

Specifies ContextMenu target to bind to.

C#
public ContextMenuBuilder Target(string value)
Parameters:valuestring

The desired target.

Returns:

ContextMenuBuilder

Example:
C#
@( Html.Kendo().ContextMenu()
.Name("ContextMenu")
.Target("#target")
)