|
<EditForm Model="@m_ModelValue">
<DataAnnotationsValidator />
<ValidationSummary />
@foreach (var field in FieldIdentifiers)
{
@field.Key
@CreateComponent(field.Key, field.Value);
<br />
}
<button type="submit">Submit</button>
</EditForm>
@code {
[Parameter] public User m_ModelValue { get; set; } = new User();
[Parameter] public Dictionary<string, string> FieldIdentifiers { get; set; } = new Dictionary<string, string> { { "FirstName", "string" }, { "Id", "bool" } };
public RenderFragment CreateComponent(string fld, string component) => builder =>
{
if (component == "string")
{
builder.OpenComponent(0, typeof(SfTextBox));
}
if (component == "bool")
{
builder.OpenComponent(0, typeof(SfCheckBox<bool>));
}
builder.CloseComponent();
};
public class User
{
[Required]
public string FirstName { get; set; }
[Required]
public bool? check { get; set; }
}
} |