如何使用具有onchange方法的输入字段从对象更新属性以写入数据?

问题描述

我正在尝试创建一个“编辑”部分来编辑对象并在数据库中更新它们:

首先,我获得当前对象并根据PropertyType(字符串=文本字段,整数=数字选择器等)加载输入字段:

对象:

enter image description here

放置输入字段:

<EditForm @ref="EditForm" Model="ObjectType" novalidate>
<DataAnnotationsValidator />
@foreach (var property in EditObject.GetType().GetProperties())
{
     @if (property.PropertyType.Name.Equals("String"))
     {
           <SfTextBox Placeholder="@property.Name"
                      Type="InputType.Text"
                      @onchange="@((Microsoft.AspNetCore.Components.ChangeEventArgs __e) => property.SetValue(EditObject,__e.Value))"
                      Value="@property.GetValue(EditObject,null)"
                      CssClass="create-model-item">
           </SfTextBox>

     }
     else if (property.PropertyType.Name.Contains("Int"))
     {
             <SfNumericTextBox TValue="int?" Placeholder="Choose a Number Value="@property.GetValue(EditObject,null)" CssClass="create-model-item">
                               <NumericTextBoxEvents TValue="int?" 
                                       ValueChange="@((Syncfusion.Blazor.Inputs.ChangeEventArgs<int?> __e) => property.SetValue(EditObject,__e.Value))">
                               </NumericTextBoxEvents>
             </SfNumericTextBox>
     }
}
<SfButton OnClick="SendForm" IsPrimary="true" CssClass="mb-3">Create</SfButton>
</EditForm>

现在,我想将“ EditObject”中属性的数据更改为用户已填写的新值,这是通过“ OnChange”方法完成的:

@onchange="@((Microsoft.AspNetCore.Components.ChangeEventArgs __e) => property.SetValue(EditObject,__e.Value))"

但是这给了我这个错误:

enter image description here

有人知道出了什么问题吗?

提前谢谢!:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)