Я хочу динамически отображать свойства поля в EditForm, но синтаксис не подходит для
Код: Выделить всё
@bind-Value="@(field.Property as string)"Код: Выделить всё
Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return typeКод: Выделить всё
@if (model != null)
{
foreach (ModelField field in model.GetFields())
{
@field.Name
@switch (field.Type)
{
case FieldType.Text:
break;
}
}
}
private IModel? model;
protected override void OnParametersSet()
{
base.OnParametersSet();
switch (Input)
{
case "test1":
model = new Test1();
break;
case "test2":
model = new Test2();
break;
}
}
Код: Выделить всё
public enum FieldType
{
Text,
Number,
}
public class ModelField
{
public object Property { get; }
public string Name { get; }
public FieldType Type { get; }
public ModelField(object property, string name, FieldType type)
{
Property = property;
Name = name;
Type = type;
}
}
Код: Выделить всё
public class Test1 : IModel
{
[Required]
public int Phone { get; set; }
[Required]
public string Message { get; set; }
public IEnumerable GetFields()
{
return new List
{
new ModelField(Phone, "Phone", FieldType.Number),
new ModelField(Message, "Message", FieldType.Text)
};
}
}
Код: Выделить всё
public interface IModel
{
IEnumerable GetFields();
}
Источник: https://stackoverflow.com/questions/781 ... ies-blazor
Мобильная версия