# Getting Started with the ActionSheet

This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC ActionSheet and highlights the major steps in the configuration of the component.

You will initialize an ActionSheet component with three items and show it over a [Card](https://demos.telerik.com/aspnet-core/cards) when a [Button](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/navigation/button/overview) is clicked.

![Sample Telerik UI for ASP.NET MVC ActionSheet](https://www.telerik.com/aspnet-mvc/documentation/assets/332a449f2df199ae3bdbf732e19c8a0b/actionsheet-getting-started.png)

## Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:

* To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can [use a project template](https://www.telerik.com/aspnet-mvc/documentation/getting-started-mvc/first-steps).

* To manually configure an existing project by using NuGet, see the [Adding Telerik UI through NuGet](https://www.telerik.com/aspnet-mvc/documentation/getting-started/setup-with-nuget).

## 1. Prepare the CSHTML File

The first step is to add the required directives at the top of the `.cshtml` document:

* To use the Telerik UI for ASP.NET MVC HtmlHelpers:

  ```cshtml
  @using Kendo.Mvc.UI
  ```

Optionally, you can structure the View content by adding the desired HTML elements like headings, divs, paragraphs, and others.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <div id="city" class="demo-view">
    </div>
```

## 2. Initialize the ActionSheet

Use the ActionSheet HtmlHelper  to add the component to a page:

* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the ActionSheet element.
* The `Title()` option specifies the title that will be displayed in the header.
* The `Items()` method configures the component items.
* The `CloseOnClick()` determines whether the ActionSheet will close when clicking outside of it
* The `ActionButtonsAlignment()` controls the alignment of the action buttons in the footer.
* The `ActionButtonOrientation()` controls the orientation of the action buttons in the footer.
* The `StartButton()` configures a start button that will be rendered in the left side of the header section of the ActionSheet.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <div id="city" class="demo-view">
        @(Html.Kendo().ActionSheet()
            .Name("actionsheet")
            .Title("Choose an option")
            .CloseOnClick(true)
            .ActionButtonsAlignment(ActionButtonsAlignment.Justify)
            .ActionButtonsOrientation(ActionButtonsOrientation.Vertical)
            .Items(items =>
            {
                items.Add().Text("Add to favorites").IconClass("k-i-heart").Click("onItemClick");
                items.Add().Text("Share").IconClass("k-i-share").Click("onItemClick");
                items.Add().Text("Comment").IconClass("k-i-comment").Click("onItemClick");
            })
            .StartButton(startButton =>
            {
                startButton
                    .Icon("pencil")
                    .Click("startButtonClick");
            })
        )
    </div>
```

## 3. Configure the Animation

Next, use the `Animation()` method to configure the effects that the component renders when the user opens and closes the ActionSheet.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <div id="city" class="demo-view">
        @(Html.Kendo().ActionSheet()
            .Name("actionsheet")
            .Title("Choose an option")
            .CloseOnClick(true)
            .ActionButtonsAlignment(ActionButtonsAlignment.Justify)
            .ActionButtonsOrientation(ActionButtonsOrientation.Vertical)
            .Items(items =>
            {
                items.Add().Text("Add to favorites").IconClass("k-i-heart").Click("onItemClick");
                items.Add().Text("Share").IconClass("k-i-share").Click("onItemClick");
                items.Add().Text("Comment").IconClass("k-i-comment").Click("onItemClick");
            })
            .Animation(animation =>
            {   
                animation.Open(open =>
                {
                    open.Expand(ExpandDirection.Horizontal);
                    open.Fade(FadeDirection.In);
                    open.Duration(500);
                });
            })
        )
    </div>
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <div id="city" class="demo-view">
        <kendo-actionsheet 
            name="actionsheet"
            title="Choose an option"
            close-on-click="true"
            action-buttons-alignment="ActionButtonsAlignment.Justify"
            action-buttons-orientation="ActionButtonsOrientation.Vertical"
        >
            <items>
                <item text="Add to Favorites" icon-class="k-i-heart" click="onItemClick" />
                <item text="Share" icon-class="k-i-share" click="onItemClick" />
                <item text="Comment" icon-class="k-i-comment" click="onItemClick" />
            </items>
            <popup-animation enabled="true">
                <open effects="expand:horizontal fade:in" duration="500" />
            </popup-animation>
        </kendo-actionsheet>
    </div>
```

## 4. Configure the Card and the Button

The next step is to define the Card and the Button components—the ActionSheet will be displayed on top of the Card when the Button is clicked.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <div id="city" class="demo-view">
        <div class="cards-container">
            <div class="k-card">
                <div class="k-card-header">
                    <h5 class="k-card-title">Rome</h5>
                    <h6 class="k-card-subtitle">Capital of Italy</h6>
                </div>
                <img class="k-card-media" alt="Telerik UI for ASP.NET Core ActionSheet Rome" src="~/shared/web/cards/rome.jpg" />
                <div class="k-card-body">
                    <p>Rome is a sprawling, cosmopolitan city with nearly 3,000 years of globally influential art, architecture and culture on display.</p>
                    <p>Ancient ruins such as the Forum and the Colosseum evoke the power of the former Roman Empire. </p>
                </div>
            </div>
        </div>
        @(Html.Kendo().Button()
            .Name("moreOptionsBtn")
            .ThemeColor(ThemeColor.Primary)
            .Content("More options")
            .Events(ev => ev.Click("moreOptionsClick"))
        )
        @(Html.Kendo().ActionSheet()
            .Name("actionsheet")
            .Title("Choose an option")
            .Items(items =>
            {
                items.Add().Text("Add to favorites").IconClass("k-i-heart").Click("onItemClick");
                items.Add().Text("Share").IconClass("k-i-share").Click("onItemClick");
                items.Add().Text("Comment").IconClass("k-i-comment").Click("onItemClick");
            })
        )
    </div>
```

Handle the `Click` event of the Button and call the [`open()`](https://docs.telerik.com/kendo-ui/api/ui/actionsheet/methods/open) client-side method to open the ActionSheet.

```JS scripts
    <script>
        function moreOptionsClick() {
            var actionsheet = $("#actionsheet").data("kendoActionSheet");
            actionsheet.open()
        }
    </script>
```

Handle the `Click` event of each ActionSheet item and call the [`close()`](https://docs.telerik.com/kendo-ui/api/ui/actionsheet/methods/close) client-side method to close the ActionSheet when an item is selected.

```JS scripts
    <script>
        function onItemClick() {
            var actionsheet = $("#actionsheet").data("kendoActionSheet");
            actionsheet.close();
        }
    </script>
```

## 5. Handle the ActionSheet Events

The ActionSheet exposes [events](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/actionsheeteventbuilder) that you can handle and further customize the functionality of the component. In this tutorial, you will use the `Activate` event to disable the <b>Share</b> ActionSheet item based on a specified condition (for example, depending on the user permissions).

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    @(Html.Kendo().ActionSheet()
        .Name("actionsheet")
        .Title("Choose an option")
        .Items(items =>
        {
            items.Add().Text("Add to favorites").IconClass("k-i-heart").Click("onItemClick");
            items.Add().Text("Share").IconClass("k-i-share").Click("onItemClick");
            items.Add().Text("Comment").IconClass("k-i-comment").Click("onItemClick");
        })
        .Events(e => e.Activate("onActivate"))
    )
```

```JS scripts
    <script>
        var isAdmin = false;
        function onActivate() {
            if(!isAdmin) {
                $(".k-actionsheet-content .k-actionsheet-item").eq(1).addClass("k-disabled"); // Disable the second item.
            }
        }
    </script>
```

## 6. (Optional) Reference Existing ActionSheet Instances

You can reference the ActionSheet instances that you have created and build on top of their existing configuration:

1. Use the `id` attribute of the component instance to get its reference.

   ```JS script
       <script>
           $(document).ready(function() {
               var actionSheetReference = $("#actionsheet").data("kendoActionSheet"); // actionSheetReference is a reference to the existing ActionSheet instance of the helper.
           });
       </script>
   ```

2. Use the [ActionSheet client-side API](https://docs.telerik.com/kendo-ui/api/ui/actionsheet#methods) to control the behavior of the component. In this example, you will enable the adaptive mode of the ActionSheet through the [`Adaptive()`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/actionsheetbuilder#adaptivesystemboolean) option and use the `fullscreen()` method to set the ActionSheet in full-screen mode dynamically (for example, when a button is clicked).

   ```Razor HtmlHelper
       @(Html.Kendo().Button()
           .Name("btn")
           .Content("Open in full-screen mode")
           .Events(ev => ev.Click("onBtnClick"))
       )

       @(Html.Kendo().ActionSheet()
           .Name("actionsheet")
           .Title("Choose an option")
           .Adaptive(true)
           .Items(items =>
           {
               items.Add().Text("Add to favorites").IconClass("k-i-heart").Click("onItemClick");
               items.Add().Text("Share").IconClass("k-i-share").Click("onItemClick");
               items.Add().Text("Comment").IconClass("k-i-comment").Click("onItemClick");
           })
       )
   ```

   ```JS scripts
       <script>
           function onBtnClick() {
               var actionSheetReference = $("#actionsheet").data("kendoActionSheet");
               actionSheetReference.fullscreen(true);
               actionSheetReference.open();
           }
       </script>
   ```

For more information on referencing specific helper instances, see the [Methods and Events](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/helper-basics/events-and-methods) article.

## Next Steps

* [Setting the ActionSheet Items](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/navigation/actionsheet/items)
* [Using the Keyboard Navigation of the ActionSheet for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-core/actionsheet/keyboard-navigation)

## See Also

* [Using the API of the ActionSheet for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/actionsheet/api)

* [Client-Side API of the ActionSheet](https://docs.telerik.com/kendo-ui/api/ui/actionsheet)

* [Server-Side API of the ActionSheet HtmlHelper](https://www.telerik.com/aspnet-mvc/documentation/api/actionsheet)

* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
