ValidationSummary

in namespace DotVVM.Framework.Controls

Displays all validation messages from the current Validation.Target.

Usage & Scenarios

Displays all validation errors in a list.

Look at the Validation tutorial to see how the validation works.

Sample 1: Basic ValidationSummary

The ValidationSummary will display all validation errors in the validation context.

<dot:TextBox Text="{value: Text}" />

<dot:ValidationSummary />

<dot:Button Text="SEND" Click="{command: Send()}" />
using System.ComponentModel.DataAnnotations;

namespace DotvvmWeb.Views.Docs.Controls.builtin.ValidationSummary.sample1
{
    public class ViewModel
    {
        [Required]
        public string Text { get; set; }

        public void Send()
        {
            // process data
        }
    }
}

Sample 2: Validation errors from child objects

By default, the ValidationSummary control displays errors that comes directly from the Validation.Target object's properties. If the validation target contains another child objects, the validation errors from those objects are not displayed. This is because of performance reasons.

However, using the IncludeErrorsFromChildren property, you can tell the control to display validation errors event from the child objects. Just be careful because there will be a performance penalty if you use this feature on large and complicated viewmodels.

<dot:TextBox Text="{value: ChildObject.Text}" />

<dot:ValidationSummary IncludeErrorsFromChildren="true" />

<dot:Button Text="SEND" Click="{command: Send()}" />
using System.ComponentModel.DataAnnotations;

namespace DotvvmWeb.Views.Docs.Controls.builtin.ValidationSummary.sample2
{
    public class ViewModel
    {
        public ChildViewModel ChildObject { get; set; } = new ChildViewModel();

        public void Send()
        {
            // process data
        }
    }

    public class ChildViewModel
    {
        [Required]
        public string Text { get; set; }
    }
}

Sample 3: Validation errors from the Validation.Target

The ValidationSummary control also displays validation errors attached directly to the Validation.Target object. This is useful for errors which do not belong to a particular property (for example, incorrect username or password).

You can disable the behavior by setting the IncludeErrorsFromTarget property to false.

The sample below creates a server-side validation error using the IValidatableObject interface.

The default value of the IncludeErrorsFromTarget property was changed in DotVVM 4.0 - previously, it was false. In DotVVM 4.0, we've decided to change this to true as it is a more reasonable default value.

<dot:TextBox Text="{value: ChildObject.Text1}" />
<dot:TextBox Text="{value: ChildObject.Text2}" />

<dot:ValidationSummary 
    Validation.Target="{value: ChildObject}"/>

<dot:Button Text="SEND" Click="{command: Send()}" />
using DotVVM.Framework.ViewModel;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace DotvvmWeb.Views.Docs.Controls.builtin.ValidationSummary.sample3
{
    public class ViewModel
    {
        public ChildViewModel ChildObject { get; set; } = new ChildViewModel();

        public void Send()
        {
            // process data
        }
    }

    public class ChildViewModel : IValidatableObject
    {
        [Required]
        public string Text1 { get; set; }

        [Required]
        public string Text2 { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Text1 != Text2)
            {
                yield return new ValidationResult("This ChildViewModel is not valid.");
            }
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon HideWhenValid Boolean Gets or sets whether this control is hidden if there are no validation messages
attribute
inner element
static value
bindable
default
False
property icon IncludeErrorsFromChildren Boolean Gets or sets whether the errors from child objects in the viewmodel will be displayed too.
attribute
inner element
static value
bindable
default
False
property icon IncludeErrorsFromTarget Boolean Gets or sets whether the errors from the TargetProperty object will be displayed too.
attribute
inner element
static value
bindable
default
True

HTML produced by the control

This control renders the HTML unordered list.

<ul data-bind="foreach: ...">
  <li data-bind="..."></li>
</ul>