English 中文(简体)
在使用参数时提交EditForm的问题
原标题:Problem when submitting EditForm when using using Parameter

我试图有一个能够发挥创建和更新作用的拉汉尔部分。 当我提交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平页降为一个领域,甚至连数据说明有效器。 这个问题依然存在。

Razor”

问题回答

这不是一个答案,而是你调查造成你的问题的起点。

页: 1 任务:Delay呼吁推广数据采集和一些AdLibing。

在你的申请中测试,以确保其发挥作用。 然后是你又做些什么,造成问题。

@page "/{Id:int?}"

<PageTitle>Index</PageTitle>

<EditForm EditContext="this._editContext" OnSubmit=this.Submit>
    <InputText @bind-Value="@_data.Value" />
    <button type="submit">Submit</button>
</EditForm>

@code {
    [Parameter] public int? Id { get; set; } = 0;
    private EditContext? _editContext;
    private MyData _data = default!;

    protected async override Task OnInitializedAsync()
    {
        _data = new MyData() { Value = "First" };
        _editContext = new EditContext(_data);

        if (this.Id > 0)
        {
            await Task.Delay(500);
            _data = new MyData() { Value = "Second" };
            _editContext = new EditContext(_data);
        }
    }

    private async Task Submit()
    {
        if (this.Id > 0)
            await Task.Delay(500);
        else
            await Task.Delay(500);
    }

    public class MyData
    {
        public string? Value { get; set; }
    }
}

我最终只是从使用空白处解答了我正在处理的项目,从来未解决这一问题。

我面临同样的情况。 对我来说,由于预先投标,功能被称作两次。 一旦残疾,表格就无问题。





相关问题
Blazor custom validation in child component

I have this component that goes into a form like <NumberWithNAAndAmberRanges2 @bind-BindNumber="LocVM.ChartDayStartMinute" NaName="Not Applicable" NaAllowed="true&...

Override/Disable Android Back Button in Blazor Hybrid MAUI

I have a .razor page which takes a lot of time to load. Is it possible to disable/override the hardware Back button in Blazor Hybrid MAUI for a specific .razor page? The primary reason for doing so is ...

Integrating Push Notifications in MAUI .NET 7 Applications

I m developing a cross-platform application using MAUI .NET 7 and I would like to add push notification functionality to my application. I m considering using Firebase Cloud Messaging or Azure ...

Blazor web assembly pass checkbox list values to model

I m new to Blazor. I m working in a web assembly Blazor project. I am trying to create a form that passes values back to a model. I have it working with input text fields and drop downs, but I am ...

热门标签