# Integrating a Cancel Button within the Form

## Environment

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

## Description

How can I integrate a **Cancel** button within the Telerik UI for ASP.NET MVC Form?

## Solution

To achieve the desired scenario:

1. Provide initial values for the Form through the `.FormData()` configuration option.
2. Configure the Form buttons through the [`.ButtonTemplateId()`](https://docs.telerik.com/aspnet-core/api/kendo.mvc.ui.fluent/formbuilder#buttonstemplateidsystemstring) configuration option and provide an `id` for the **Cancel** button.
3. Attach a click handler for the **Cancel** button.
4. Within the handler, get the `formData`, set the `form` fields programmatically, and make an Ajax request to the desired end-point.

```Razor Form.cshtml
@model FormPostModel.Models.Team

    @(Html.Kendo().Form<FormPostModel.Models.Team>()
        .Name("formExample")
        .HtmlAttributes(new { action = Url.Action("Index","Home"), method = "POST" })
        .ButtonsTemplateId("buttonsTemplate")
        .Items(items =>
        {
            items.AddGroup()
                .Label("Add/Edit Teams")
                .Items(i =>
                {

                    i.Add()
                            .Field(f => f.TeamName)
                            .Label(l => l.Text("Team Name:")
                            );
                    i.Add()
                        .Field(f=>f.Countries)
                        .Editor(e=>e.CheckBoxGroup()
                            .Items(items=>{
                                items.Add().Label("Bulgaria").Value("1");
                                items.Add().Label("England").Value("2");
                                items.Add().Label("France").Value("3");
                            })
                        );
                    i.Add()
                        .Field(f => f.Description)
                        .Editor(e=> e.TextBox())
                        .Label(l => l.Text("Description Name:"));

                });
        }).FormData(Model)
    )

    <script id="buttonsTemplate" type="text/x-kendo-template">
        <div class="myButtonsContainer">
            <button class="k-button k-button-primary k-form-submit" type="submit">
                <span class="k-button-text">My Submit Submit</span>
            </button>
            <button id="cancelBtn" type="button" class="k-button">
                <span class="k-button-text"> My Cancel Button</span>
            </button>
        </div>
    </script>

```

```JS script.js
   $(document).ready(function(){
         $("#cancelBtn").on("click",function(e){
            var form=$("#formExample").data("kendoForm");
            var formData=form.options.formData;
            form.editable.options.model.set("TeamName", formData.TeamName);
            form.editable.options.model.set("Description", formData.Description);
            form.editable.options.model.set("Countries", formData.Countries);
        })
   })
```

## More ASP.NET MVC Form Resources

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

* [ASP.NET MVC Form Demos](https://demos.telerik.com/aspnet-mvc/form)

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

* [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 Form for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/form)
* [Server-Side API Reference of the Form for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/form)
* [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)
