Blazor List Of Strings Input Binding

Viewed 2433

I'm trying to display a list of strings and I want the user to be able to edit the list to make changes to the object but when I view the list after modifying the input fields the changes haven't been made.

How do I bind a list of strings?

 @foreach (var message in UserMessageService.GetSomeData())
    {
    <tr>
        <td><input type="text" bind="@message.Username" value="@message.Username" onblur="SaveMessages"/></td>
        <td><input type="text" bind="@message.Message" value="@message.Message" onblur="SaveMessages"/></td>
    </tr>
    }
2 Answers

silly mistake on my part, the issue wasn't with my syntax. I made the mistake of binding to my service instead of a local variable so when I left focus it couldn't update and just retrieved from the service

I simply added the local variable below

        @foreach (var message in dataVariable)
        {
        <tr>
            <td><input type="text" @bind="message.Username" /></td>
            <td><input type="text" @bind="message.Message" /></td>
        </tr>
        }

   @code {
    private List<someData> dataVariable;

    protected override void OnInitialized()
    {
        TableSeats = UserMessageService.GetSomeData();
    }
}
Related