Closed pimber closed 5 months ago
I confirm. I have the same problem.
That's how the code started working correctly.
@page "/"
<EditForm Model="Model" OnSubmit="Submit" FormName="Form1" Enhance>
<InputText @bind-Value="Model!.Name" />
<button type="submit" >Submit</button>
</EditForm>
@code {
[SupplyParameterFromForm]
public Starship? Model { get; set; } = new();
protected override void OnInitialized()
{
Model!.Name ??= "init value";
}
private void Submit()
{
Console.WriteLine($"Name: {Model!.Name}");
}
public class Starship
{
public int Id { get; set; }
public string? Name { get; set; }
}
}
I can confirm that your proposed solution works. But that did not solve my issue unfortunately.
After a lot of debugging, i found out that the name attribute on the Input* classes somehow breaks the binding or is the issue some how. Example on what the InputText looks like when it breaks/is the issue:
When clicking on the submit button, it breaks when i have the name attribute on:
<InputText @bind-Value="complete_recipe.name" class="form-control" id="name" name="name"/>
When i removed the name attribute, it works.
<InputText @bind-Value="complete_recipe.name" class="form-control" id="name"/>
@gitEugeneL I have tested this with your posted code aswell, and it also breaks when you add the name attribute on the Input* classes.
@page "/"
@code { [SupplyParameterFromForm] private Tester Test { get; set; }
protected override void OnInitialized() => Test ??= new();
private void HandleSubmit() {
Console.WriteLine($"Name: {Test?.Name}");
}
private class Tester
{
public int Id { get; set; }
public string Name { get; set; }
}
}
This solution work for me
Is there an existing issue for this?
Describe the bug
When using the EditForm component, the value from the Input* classes are not bounded correctly to the model.
Expected Behavior
I expect that the values from the Input* classes bounds correctly to the model, so that i can get the information from the frontend to the backend.
Steps To Reproduce
@code { private Tester Test = new();
}