mardi 18 octobre 2022

Checkbox default value


    <div class="form-group mb-2">
            <label asp-for="@Model.ProductDTO.Discontinued" class="col-sm-2 col-form-label">Discontinued</label>
            <input type="checkbox" asp-for="@Model.ProductDTO.Discontinued" name="Discontinued" />
        </div>

public bool? Discontinued { get; set; }


    InvalidOperationException: Unexpected 'asp-for' expression result type 'System.Nullable`1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' for <input>. 'asp-for' must be of type 'System.Boolean' or 'System.String' that can be parsed as a 'System.Boolean' if 'type' is 'checkbox'.

The Discontinued model is NUllable so checkbox can be nullable. How can I do that?




Aucun commentaire:

Enregistrer un commentaire