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

ContextMenuBuilder

Methods

Animation(System.Boolean)

Toggles the ContextMenu Animation.

Parameters

enable - System.Boolean

Boolean parameter.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Animation(false)
                        .Items(items =>
                        {
                            items.Add().Text("First Item");
                            items.Add().Text("Second Item");
                        })
            )

Animation(System.Action)

Sets the Animation options.

Parameters

animationAction - System.Action<PopupAnimationBuilder>

The animation settings.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Animation(a => a.Open(o => o.Expand(ExpandDirection.Vertical)))
                        .Items(items =>
                        {
                            items.Add().Text("First Item");
                            items.Add().Text("Second Item");
                        })
            )

Items(System.Action)

Defines the items in the menu.

Parameters

addAction - System.Action<ContextMenuItemFactory>

The add action.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Items(items =>
                        {
                            items.Add().Text("First Item");
                            items.Add().Text("Second Item");
                        })
            )

Events(System.Action)

Configures the client-side events.

Parameters

clientEventsAction - System.Action<ContextMenuEventBuilder>

The client events action.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Events(events =>
                            events.Open("onOpen").OnClose("onClose")
                        )
            )

DataSource(System.Action)

Configure the DataSource of the component

Parameters

configurator - System.Action<HierarchicalDataSourceBuilder>

The action that configures the DataSource.

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataSource(dataSource => dataSource
                    .Read(read => read
                        .Action("GetData", "Home")
                    )
                )
             )

DataSource(System.String)

Sets the DataSource ID of the component

Parameters

dataSourceId - System.String

Configures the DataSource ID.

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataSource("dataSourceId")
             )

DataTextField(System.String)

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

Parameters

value - System.String

The value for DataTextField

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataTextField("Name")
             )

DataUrlField(System.String)

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

Parameters

value - System.String

The value for DataUrlField

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataUrlField("UrlField")
             )

DataSpriteCssClassField(System.String)

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

Parameters

value - System.String

The value for DataSpriteCssClassField

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataSpriteCssClassField("CSSField")
             )

DataImageUrlField(System.String)

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

Parameters

value - System.String

The value for DataImageUrlField

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataImageUrlField("ImageUrlField")
             )

DataContentField(System.String)

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

Parameters

value - System.String

The value for DataContentField

Example


             @( Html.Kendo().ContextMenu()
                .Name("ContextMenu")
                .DataContentField("ContentField")
             )

Direction(Kendo.Mvc.UI.ContextMenuDirection)

Specifies ContextMenu opening direction.

Parameters

value - ContextMenuDirection

The desired direction.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Direction(ContextMenuDirection.Left)
            )

Direction(System.String)

Specifies ContextMenu opening direction.

Parameters

value - System.String

The desired direction.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Direction("top")
            )

Target(System.String)

Specifies ContextMenu target to bind to.

Parameters

value - System.String

The desired target.

Example


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

Filter(System.String)

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

Parameters

value - System.String

The desired filter.

Example


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

ShowOn(System.String)

Specifies ContextMenu triggering event.

Parameters

value - System.String

The desired event.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .ShowOn("click")
            )

Orientation(Kendo.Mvc.UI.ContextMenuOrientation)

Sets the menu orientation.

Parameters

value - ContextMenuOrientation

The desired orientation.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .Orientation(ContextMenuOrientation.Vertical)
            )

OpenOnClick(System.Boolean)

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

Parameters

value - System.Boolean

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .OpenOnClick(true)
            )

CloseOnClick(System.Boolean)

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

Parameters

value - System.Boolean

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .CloseOnClick(false)
            )

AlignToAnchor(System.Boolean)

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

Parameters

value - System.Boolean

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .AlignToAnchor(false)
            )

AppendTo(System.String)

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

Parameters

value - System.String

The value for AppendTo

Example


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

HoverDelay(System.Int32)

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

Parameters

value - System.Int32

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .HoverDelay(300)
            )

BindTo(System.String,System.Action)

Binds the menu to a sitemap

Parameters

viewDataKey - System.String

The view data key.

siteMapAction - System.Action<ContextMenuItem,SiteMapNode>

The action to configure the item.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .BindTo("examples", (item, siteMapNode) =>
                        {
                        })
            )

BindTo(System.String)

Binds the menu to a sitemap.

Parameters

viewDataKey - System.String

The view data key.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .BindTo("examples")
            )

BindTo(System.Collections.Generic.IEnumerable,System.Action)

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.

Parameters

dataSource - System.Collections.Generic.IEnumerable<T>

The data source.

itemDataBound - System.Action<ContextMenuItem,T>

The action executed for every data bound item.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .BindTo(new []{"First", "Second"}, (item, value) =>
                        {
                           item.Text = value;
                        })
            )

BindTo(System.Collections.IEnumerable,System.Action)

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

Parameters

dataSource - System.Collections.IEnumerable

The data source.

factoryAction - System.Action<NavigationBindingFactory>

The action which will configure the mappings

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .BindTo(Model, mapping => mapping
                                .For<Customer>(binding => binding
                                    .Children(c => c.Orders) // The "child" items will be bound to the the "Orders" property
                                    .ItemDataBound((item, c) => item.Text = c.ContactName) // Map "Customer" properties to ContextMenuItem properties
                                )
                                .For<Order<(binding => binding
                                    .Children(o => null) // "Orders" do not have child objects so return "null"
                                    .ItemDataBound((item, o) => item.Text = o.OrderID.ToString()) // Map "Order" properties to ContextMenuItem properties
                                )
                        )
            )

BindTo(System.Collections.Generic.IEnumerable)

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 method.

Parameters

items - System.Collections.Generic.IEnumerable<ContextMenuItem>

The list of items

Example


             @( Html.Kendo().ContextMenu()
                        .Name("TreeView")
                        .BindTo(model)
            )

ItemAction(System.Action)

Callback for each item.

Parameters

action - System.Action<ContextMenuItem>

Action, which will be executed for each item.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .ItemAction(item =>
                        {
                            item
                                .Text(...)
                                .HtmlAttributes(...);
                        })
            )

HighlightPath(System.Boolean)

Select item depending on the current URL.

Parameters

value - System.Boolean

If true the item will be highlighted.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .HighlightPath(true)
            )

SecurityTrimming(System.Boolean)

Enable/disable security trimming functionality of the component.

Parameters

value - System.Boolean

If true security trimming is enabled.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .SecurityTrimming(false)
            )

SecurityTrimming(System.Action)

Defines the security trimming functionality of the component

Parameters

securityTrimmingAction - System.Action<SecurityTrimmingBuilder>

The securityTrimming action.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("ContextMenu")
                        .SecurityTrimming(builder =>
                        {
                            builder.Enabled(true).HideParent(true);
                        })
            )

Scrollable(System.Action)

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.

Parameters

scrollableAction - System.Action<ContextMenuScrollableBuilder>

Example


             @( Html.Kendo().ContextMenu()
                        .Name("Menu")
                        .Scrollable(s => s.Distance(300))
            )

Scrollable(System.Boolean)

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.

Parameters

enabled - System.Boolean

Boolean flag.

Example


             @( Html.Kendo().ContextMenu()
                        .Name("Menu")
                        .Scrollable(true)
            )

ToComponent()

Returns the internal view component.

Name(System.String)

Sets the name of the component.

Parameters

componentName - System.String

The name of the component.

Example


            @(Html.Kendo().Grid<OrderViewModel>()
               .Name("grid")
               .Columns(columns =>
               {
                   columns.Bound(p => p.OrderID).Filterable(false);
                   columns.Bound(p => p.Freight);
               })
               .DataSource(dataSource => dataSource
                   .Ajax()
                   .PageSize(20)
                   .Read(read => read.Action("Orders_Read", "Grid"))
               )
            )

Deferred(System.Boolean)

Suppress initialization script rendering. Note that this options should be used in conjunction with

Parameters

deferred - System.Boolean

ModelMetadata(System.Web.Mvc.ModelMetadata)

Uses the Metadata of the Model.

Parameters

modelMetadata - System.Web.Mvc.ModelMetadata

The metadata set for the Model

HtmlAttributes(System.Object)

Sets the HTML attributes.

Parameters

attributes - System.Object

The HTML attributes.

HtmlAttributes(System.Collections.Generic.IDictionary)

Parameters

attributes - System.Collections.Generic.IDictionary<String,Object>

AsModule(System.Boolean)

Specifies whether the initialization script of the component will be rendered as a JavaScript module.

Parameters

value - System.Boolean

Render()

Renders the component.

Example


            @(@Page Inherits="System.Web.Mvc.ViewPage<IEnumerable<Product>>" )
            @( Html.Kendo().Grid(Model)
                .Name("grid")
                .DetailTemplate(product => {
                    )
                       Product Details:
                       <div>Product Name: @( product.ProductName )</div>
                       <div>Units In Stock: @( product.UnitsInStock )</div>
                    @(
                })
                .Render();
            )

ScriptAttributes(System.Object,System.Boolean)

Sets the JavaScript attributes to the initialization script.

Parameters

attributes - System.Object

The JavaScript attributes.

overrideAttributes - System.Boolean

Argument which determines whether attributes should be overriden.

ScriptAttributes(System.Collections.Generic.IDictionary,System.Boolean)

Sets the JavaScript attributes to the initialization script.

Parameters

attributes - System.Collections.Generic.IDictionary<String,Object>

The JavaScript attributes.

overrideAttributes - System.Boolean

Argument which determines whether attributes should be overriden.

ToHtmlString()

ToClientTemplate()

In this article
Not finding the help you need?