Reputation: 756
I'm trying to set the id of a @Html.CheckBoxFor using data from the page model.
@Html.CheckBoxFor(modelItem => item.IsOpen, htmlAttributes: new { @class = "custom-control-input switcher", @disabled = "disabled", @id = "[email protected]" })
The last part "[email protected]" is not working, I would like it to render: id="cbxOpen_1" where 1 is the item id. But it obviously renders as a string e.g. id="[email protected]"
Is there a way to make it use the data?
Upvotes: 1
Views: 644
Reputation: 14640
Just handle it as you would in C# normally:
@id = $"cbxOpen_{item.Id}"
Upvotes: 0
Reputation: 4373
Change this part @id = "[email protected]"
to @id = "cbxOpen_" & item.Id
Upvotes: 2