2

I am a beginner in Blazor

Im not getting any error and why two way data binding not working,

I'm experiencing a two-way data binding issue in my Blazor WebAssembly app. I have a checkbox bound to a boolean property IsActive in my viewmodel. When I toggle the checkbox, the property doesn't update. Here's my code:

I've tried using @bind-value and @bind-value:event="oninput" but it doesn't seem to work. Any help would be appreciated!"

I'm building a Blazor WebAssembly app and I'm experiencing a two-way data binding issue. I have a checkbox that's bound to a boolean property IsActive in my viewmodel. When I toggle the checkbox, the property doesn't update, and vice versa - when I update the property in code, the checkbox doesn't reflect the change.

Here is my code in

namespace HiddenVilla_Server.Model
{
    public class BlazorRoom
    {
        public int Id { get; set; }
        public string RoomName { get; set; }
        public double Price { get; set; }
        public bool IsActive { get; set; }
    }
}


<h2 class="bg-light border p-2">
    First Room

</h2>
    Room: @Room.RoomName
<br />
    Price: @Room.Price
<br />

<input type="number" @bind-value="Room.Price" @bind-value:event="oninput" />
<br />
<input type="checkbox" @bind-value="Room.IsActive" checked="@(Room.IsActive?"checked":null)" /> &nbsp; Is Active
<br />
<span>This room is @(Room.IsActive ? "Active" : "Inactive")</span>
<br />


    Room: @Room.RoomName
<br />
    Price: @Room.Price
<br />


@code{
    BlazorRoom Room = new BlazorRoom()
    {
        Id = 1,
        RoomName = "Villa Suite",
        IsActive = true,
        Price = 599
    };
 
}

Error messages:

None, the app runs without errors, but the binding doesn't work as expected.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.