# Passing a Parameter Dynamically to a Dialog Action Button

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Dialog</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.3.1010 version</td>
 </tr>
</table>

## Description

How can I pass a parameter dynamically to a specified action button of a Dialog before opening the Dialog?

## Solution

1. Create a [`Button`](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/navigation/button/overview) to open the Dialog when clicked.
2. Get a reference to the hidden Dialog within the Button's [`Click`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/buttoneventbuilder#clicksystemstring) event handler.
3. Access the current actions configuration of the Dialog.
4. Set a new callback function of the Action and pass the desired parameter.
5. Call the `setOptions()` method to update the Dialog's actions settings.
6. Open the Dialog by using the `open()` method.

   ```Razor HtmlHelper
       @(Html.Kendo().Button()
           .Name("openDialogBtn")
           .Content("Open Dialog")
           .Events(ev=>ev.Click("onClick"))
       )

       @(Html.Kendo().Dialog()
           .Name("dialog")
           .Title("Confirm Remove User")
           .Content("<p>Are you sure you want to Remove this User?<p>")
           .Width(400)
           .Modal(true)
           .Actions(actions =>
           {
               actions.Add().Text("Cancel");
               actions.Add().Text("Confirm").Action("onConfirmRemoveUser").Primary(true);
           })
           .Visible(false)
       )
   ```

   ```JS script
       <script>
           function onClick() {
               var customParam = "ABC123";
               var dialog = $('#dialog').data("kendoDialog");
               let dialogActions = dialog.options.actions;
               dialogActions[1].action = function() { // Update the callback function of the "Confirm" action.
                   return onConfirmRemoveUser(customParam);
               };
               dialog.setOptions({actions: dialogActions});
               dialog.open();
           }

           function onConfirmRemoveUser(idParam) {
               alert(idParam);
           }
       </script>
   ```

For a runnable example based on the code above, refer to the [REPL example on passing a parameter dynamically to a specified action button of the Dialog](https://netcorerepl.telerik.com/wRFacjOW08flKnDM08).

## More ASP.NET MVC Dialog Resources

* [ASP.NET MVC Dialog Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/layout/dialog/overview)

* [ASP.NET MVC Dialog Demos](https://demos.telerik.com/aspnet-mvc/dialog/index)

* [ASP.NET MVC Dialog Product Page](https://www.telerik.com/aspnet-mvc/dialog-for-mvc)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Dialog for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/dialog)

* [Server-Side API Reference of the Dialog for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/dialog)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
