I have a checkbox and when I press it, I need to add checked
attribute to cshtml.
When I deselect the checkbox, I need to remove this attribute. How can I do it?
Now, when I press it, nothing is happens. I need to change the value of Checked
variable somehow.
View model:
public class ListProductVM
{
public int Id { get; set; }
public bool Checked { get; set; }
}
.cshtml
page:
<div class="compare-checkbox form-checkbox">
<input name="compare-@Model.Id" class="js-favorite-checkbox" type="checkbox" @(Model.Checked ? "checked" : "") data-product-id="@Model.Id">
</div>