Reputation: 3563
In my view I have a checkbox and I need to add an attribute to it when I select product on the page. I can't understand, how to dynamically add or remove this attribute? Now I wrote it in cshtml and all itens on page are checked, but I need to show this attribute only when user press on the checkbox.
public class ListProductVM
{
public int Id { get; set; }
public bool Checked { get; set; }
}
_ListProduct.cshtml
@model Bs.WebApp.ViewModels.Product.Shared.ListProductVM
<div class="compare-checkbox form-checkbox"> // This
<input name="[email protected]" class="js-favorite-checkbox" checked type="checkbox" data-product-id="@Model.Id">
</div>
Upvotes: 1
Views: 346
Reputation: 1
You can use this way to check if your model is checked or not:
<input @(Model.Checked ? "checked" : "") name="[email protected]" class="js-favorite-checkbox" type="checkbox" data-product-id="@Model.Id">
Upvotes: 1