# Displaying a Validation Summary in a Dialog

## 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 2022.2.621 version</td>
 </tr>
</table>

## Description

How can I show a validation summary in the Telerik UI for ASP.NET MVC Dialog?

## Solution

1. Set an initial HTML content within the Dialog which will act as a container for the error messages.
2. Get the reference of the validator and attach a handler to the `validate` event through the `.bind()` configuration method.
3. Within the handler, assess if any errors have occurred by using the `.errors()` method. Based on the evaluation, append the error messages to the content of the Dialog and open it.

```Razor Index.cshtml
    <form id="myform">
        <input name="username" required /> <br />
        <input name="password" required /> <br />
        <button>Validate</button>
    </form>

    @(Html.Kendo().Dialog()
            .Name("SMEValidationSummary")
            .Title("SME Validation Summary")
            .Closable(false)
            .Content("<div class='errors'></div>")
            .Width(400)
            .Modal(true)
            .Visible(false)
            .Actions(actions =>
            {
                actions.Add().Text("OK").Primary(true);
            })
    )
```

```JS script.js
    $(document).ready(function(){
        var validator = $("#myform").kendoValidator().data("kendoValidator");
        validator.bind("validate", function (e) {        
                var errors = this.errors();
                
                if (errors.length) {
                    var html = "<ul style='color:red;'>";
                    for (var i = 0; i < errors.length; i++) {
                        html += "<li>" + errors[i] + "</li>";
                    }
                    html += "</ul>";
                    $(".errors").html($(html));
                    $("#SMEValidationSummary").data("kendoDialog").open();
                }
        });
    })
```

For the complete implementation of the suggested approach, refer to the following [Telerik REPL](https://netcorerepl.telerik.com/cmasECbw25M5uiBi06) example.

## 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)

* [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

* [Telerik REPL: Displaying a Validation Summary in a Dialog](https://netcorerepl.telerik.com/cmasECbw25M5uiBi06)
* [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)
