Blazor EditForm Submission Issue: modeltodoTask Empty on Submit

Umut Can 0 Reputation points
2024-01-18T22:03:01.4966667+00:00

I fill in the modeltodoTask objects with Editform and send them to the "AddTask()" function, but when I check the data before adding them, they are all empty. 1-) modeltodoTask.Text= must be the value to be filled in the form. 2-) I want the value "modeltodoTask.StatusId=Status.Id" My goal is to create a todolist app and save the newly added tasks to the database with the id value of the form they are in. https://github.com/iamumutcan/ToDoListApp


private IEnumerable<TodoStatus> Statuses { get; set; } = new List<TodoStatus>();
private IEnumerable<TodoStatus> OtherStatuses { get; set; } = new List<TodoStatus>();
private IEnumerable<TodoTask> Tasks { get; set; } = new List<TodoTask>();
public TodoTask todoTask = new TodoTask();
private TodoTask modeltodoTask { get; set; } = new TodoTask();

public bool IsLoading { get; set; } = true;
protected override async Task OnInitializedAsync()
{
    Statuses = await _statusRepository.GetAllWithTasks();
    OtherStatuses = await _statusRepository.GetAll();
    IsLoading = false;
    modeltodoTask ??= new();
    await Task.CompletedTask;

}

public List<TodoStatus> GetByIdExcludingAsync(int id)
{
    return OtherStatuses.Where(x => x.Id != id).ToList();
}

public async Task AddTask()
{
    await _taskRepository.Create(modeltodoTask);
}
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,662 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 71,101 Reputation points
    2024-01-18T23:21:33.0366667+00:00

    in your component you are only doing one-way binding as you only define the get, not the event binding:

             <InputText @bind-Value="modeltodoTask.Text"></InputText>
    

    try the @bind helper (which maps the onchange event) instead:

             <InputText @bind="modeltodoTask.Text"></InputText>
    

    please read the docs on binding:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.