Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Validatation Message Not working With Blazor Using Generic

$
0
0

In Blazor 8 Web Assembly (maybe other hosting models), ValidationMessage does not display when using Generic model in the component. Here is an example. Looks like I have to do something with the Forexpression but what?

    @typeparam TModel where TModel : class, new()<EditForm Context="editFormComponent" OnValidSubmit="@HandleValidSubmit" Model="@model"><DataAnnotationsValidator /><h4>Validation Summary</h4><ValidationSummary />        @foreach (var property in model.GetType().GetProperties())        {            var propertyValue = property.GetValue(model)?.ToString();<div class="row mb-3"><div class="col"><div class="form-group"><input @onchange='((e) => HandleValueChanged(e, property.Name))'                               type="text"                               value=@propertyValue                               class="form-control" /></div></div></div><h5>Validation Message</h5><ValidationMessage For=@(() => property.Name) />

enter image description here

I want to look like this:

enter image description here


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>