-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed as not planned
Closed as not planned
Copy link
Labels
affected-fewThis issue impacts only small number of customersThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureFeatures related to the built in components we ship or could ship in the futureseverity-majorThis label is used by an internal toolThis label is used by an internal tool
Milestone
Description
Thank you for your effors to build awesome Blazor.
I want to create dynamic form using Reflection for TValue: Value as:
<EditForm Model="Value" OnValidSubmit="OnvalidSubmit" OnInvalidSubmit="OnInValidSubmit" class="@formStyle">
<DataAnnotationsValidator />
@{
var properties = Value.InputFields;
@foreach (var p in properties)
{
var att = p.GetCustomAttributes(false);
if (!att.Any(c => c is HiddenAttribute))
{
var nameAttribute = (DisplayAttribute)att.FirstOrDefault(c => c is DisplayAttribute);
var value = p.GetValue(Value);
<div class="form-group">
@if (nameAttribute != null)
{
<label for="@p.Name">
@nameAttribute.Name
@if (att.Any(c => c is RequiredAttribute))
{
<font color="red">(*)</font>
}
</label>
}
<InputText class="form-control" Value="@value?.ToString()" ValueExpression="@(() => p.Name)" ValueChanged="(e => p.SetValue(Value, e))" />
<ValidationMessage For="@(() => p)"></ValidationMessage>
</div>
}
}
}
<button type="submit" class="btn btn-primary">Click me</button>
</EditForm>In MVC, i found a way for that Here.
I think ValidationMessage can support PropertyInfo
<ValidationMessage Model="@Value" NameField="p.Name"></ValidationMessage>
Metadata
Metadata
Assignees
Labels
affected-fewThis issue impacts only small number of customersThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureFeatures related to the built in components we ship or could ship in the futureseverity-majorThis label is used by an internal toolThis label is used by an internal tool