Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

c# - EditForm in Blazor with two InputSelects, submit button doesn't seem ike it fires

I have two InputSelects that get their options from two tables. Their values write to another table that's basically a lookup table. So, two integer values, and an ID for that row.

@page "/utility/ptrh"
@inject IProviderTypeRespiteHomeRepo Repo
@inject IRespiteHomeRepo RhRepo
@inject IProviderTypeRepo PtRepo
@inject NavigationManager NavManager
@inject IToastService ToastService

<h3>Assign Provider Type to Respite Home</h3>

<EditForm Model="_model" OnSubmit="CreatePtrh">
    <DataAnnotationsValidator />
    <ValidationSummary />
    <div class="form-group">
        <label for="rh">Respite Home</label>
        @*<InputNumber @bind-Value="_model.RespiteHomeId"></InputNumber>*@
        <InputSelect @bind-Value="_model.RespiteHomeId" class="form-control" id="rh">
            @if (_rhModel != null)
            {
                <option value="-1">select one</option>
                @foreach (var rh in _rhModel)
                {
                    <option value="@rh.ID">@rh.RespiteHomeName</option>
                }
            }
        </InputSelect>
    </div>
    <div class="form-group">
        <label for="pt">Provider Type</label>
        @*<InputNumber @bind-Value="_model.ProviderTypeId"></InputNumber>*@
        <InputSelect @bind-Value="_model.ProviderTypeId" class="form-control" id="pt">
            @if (_ptModel != null)
            {
                <option value="-1">select one</option>
                @foreach (var pt in _ptModel)
                {
                    <option value="@pt.ID">@pt.ProviderTypeName</option>
                }
            }
        </InputSelect>
    </div>
    
    <button class="btn btn-success" type="submit"><span class="oi oi-pencil"></span> Add Provider Type for Respite Home</button>

    <button @onclick="BackToList" class="btn btn-outline-secondary">
        <span class="oi oi-media-skip-backward"></span> Back to List
    </button>
</EditForm>

@code {
    private ProviderTypeRespiteHome _model = new ProviderTypeRespiteHome();
    private IList<RespiteHome> _rhModel;
    private IList<ProviderType> _ptModel;
    private bool _isSuccess = true;

    protected override async Task OnInitializedAsync()
    {
        _rhModel = await RhRepo.Get(Endpoints.RespiteHomeTypesEndpoint);
        _ptModel = await PtRepo.Get(Endpoints.ProviderTypesEndpoint);
    }

    private async Task CreatePtrh()
    {
        _isSuccess = await Repo.Create(Endpoints.PTRHEndpoint, _model);
        if (_isSuccess)
        {
            ToastService.ShowSuccess("PTRH record has been created.");
            BackToList();
        }
    }

    private void BackToList()
    {
        NavManager.NavigateTo("/respitehomes/");
    }
}

My data models are OK. They pull the data from the other two tables OK. Just when I hit the submit button, nothing happens.

Help! Other create razor pages with almost the same markup work!!!!

question from:https://stackoverflow.com/questions/65907884/editform-in-blazor-with-two-inputselects-submit-button-doesnt-seem-ike-it-fire

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As in the comment above, make sure you don't have MORE THAN ONE controller in your API that has the exact same name, even if it's in another folder or sub-folder. Once deleted, it works just fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...