title: Blazor trigger custom validation message
body: <p>I have the following class which is being used as an input model for an EditForm in a Blazor server side application.</p>
  <pre><code>public class KundeInput
  {
      [ValidateComplexType]
      public List&lt;AnsprechpartnerInput&gt; Ansprechpartner { get; } = new List&lt;AnsprechpartnerInput&gt;();
    
      public string? Kundennummer { get; }
   
      [Required]
      [MaxLength(60)]
      public string Firma { get; set; } = String.Empty;
      [MaxLength(60)]
      public string? Name2 { get; set; }
      [MaxLength(60)]
      public string? Name3 { get; set; }
  }
  </code></pre>
  <p>As you can see, my model contains a list of another model called AnsprechpartnerInput. Here is this model:</p>
  <pre><code>public class AnsprechpartnerInput
  {
      public string? Kundennummer { get; set; }
      public int Nummer { get; } = -1;
      [MaxLength(60)]
      [Required]
      public string Vorname { get; set; } = String.Empty;
      [MaxLength(60)]
      [Required]
      public string Nachname { get; set; } = String.Empty;
      [MaxLength(40)]
      [Required]
      public string? Bereich { get; set; }
      / * More properties */
  }
  </code></pre>
  <p>The validation works fine. However, once I have multiple invalid AnsprechpartnerInput models in my list, the ValidationSummary becomes a mess. Because it displays e.g. 5 times field xyz is invalid.</p>
  <p>I know I can set a custom message with the ErrorMessage property but I am not able to use other attributes from my model in this message.</p>
  <p>What I want to achive is this:</p>
  <pre><code>[Required(ErrorMessage = $&quot;Vorname of {Kundennummer} is required&quot;)]
  public string Vorname { get; set; } = String.Empty;
  </code></pre>
  <p>I already tried to change the message with reflection but accoridng to Microsoft this way is not recommend or supported
  <a href="https://github.com/dotnet/aspnetcore/issues/25611" rel="nofollow noreferrer">https://github.com/dotnet/aspnetcore/issues/25611</a></p>
  <p>Is there any way to get it to work? I thought of string replacement but I am not sure how I can figure out the right model for my ValidationMessage.</p>
  <p>Also is there any way to validate the items of the list by one and get a boolean result? Let's say I want to achive this:</p>
  <pre><code>@foreach (var ansprechpartner in Input.Ansprechpartner)
  {
  
      if (Input.SelectedAnsprechpartner is null)
          Input.SelectedAnsprechpartner = ansprechpartner;
  
      &lt;a @onclick=&quot;() =&gt; Input.SelectedAnsprechpartner = ansprechpartner&quot;
         class=&quot;@GetNavListClass(Input.SelectedAnsprechpartner == ansprechpartner)&quot;
         id=&quot;list-ansprechpartner-tab-@(ansprechpartner.Nummer)&quot;
         data-toggle=&quot;list&quot;
         href=&quot;#list-ansprechpartner-@(ansprechpartner.Nummer)&quot;
         role=&quot;tab&quot;
         aria-controls=&quot;@(ansprechpartner.Nummer)&quot;&gt;
          @((MarkupString)(ansprechpartner.Nummer &lt; 0  ? &quot;&lt;span class=\&quot;font-weight-bold\&quot;&gt;NEU&lt;/span&gt;&quot; : $&quot;({ansprechpartner.Nummer})&quot;)) @ansprechpartner.Vorname @ansprechpartner.Nachname
      &lt;/a&gt;
      // When the model ansprechpartner is invalid, I want to display an icon
  }
  </code></pre>
  <p>Thanks for any help!
  PS: Blazor rocks!</p>