我试图有一个能够发挥创建和更新作用的拉汉尔部分。 当我提交EditForm时,在途中没有经过一个参数,则要求提交文件功能,但在我通过一个参数并用现有数据填满我的编辑时,提交文件只是更新了造成OnInitializedAsync再次被触发的网页和我将要失去的改动。
public partial class PersonalInfo
{
private PersonalInfoModel _personalInfo = new PersonalInfoModel();
private EditContext _editContext;
private Response _customerResponse;
[Parameter]
public int? CustomerId { get; set; }
[Inject]
public CustomerService CustomerSvc { get; set; }
[Inject]
public NavigationManager NavManager { get; set; }
protected override async Task OnInitializedAsync()
{
_editContext = new EditContext(_personalInfo);
_customerResponse = await CustomerSvc.GetCustomer(CustomerId ?? 0);
if (_customerResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
_personalInfo = _customerResponse.Content.Serialize().Deserialize<PersonalInfoModel>();
_editContext = new EditContext(_personalInfo);
}
}
private async Task Submit()
{
int customerId;
if (_customerResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
customerId = await CustomerSvc.UpdateCustomer(_personalInfo);
}
else
{
customerId = await CustomerSvc.CreateCustomer(_personalInfo);
}
}
Razor”
@page "/PersonalInfo/{CustomerId:int?}"
<EditForm EditContext="_editContext" OnValidSubmit="@Submit">
</EditForm>
最新情况:
我将raz平页降为一个领域,甚至连数据说明有效器。 这个问题依然存在。