vendredi 21 février 2020

Setting chekbox value using Blazor without binding

this is probably easy, but i'm kind of stuck. I'm reading data from a DB and need a chekbox to reflect the current status of a bool, I can get the status in code but cant figur out how to add or remove the "checked" property of the checkbox input. I'm using @onchange to call a function and can't use @Bind. I asume that i can creat a function that returns the values: "" or "checked" and just call it inside of the tag, but this won't work.

this is my input:

<input type="checkbox" class="form-control" value="test" @BoolChecker() @onchange="@function1()" />

and this is the function BoolChecker():

public string BoolChecker()
        {
            if (mybool != null) {
                return (mybool == true) ? "checked" : "");
            }
            else
            {
                return "";
            }
        }

where can i place the BoolChecker function to make this work? if it isen't clear it is suppose to make the checkbox appear checked if the BoolChecker function returns "checked" (and mybool is true)




Aucun commentaire:

Enregistrer un commentaire