How to add model value to html attribute value

I have this code

@if (ViewBag.TechnologyNames != null) { foreach (var technologyName in ViewBag.TechnologyNames) { if (@technologyName.TechnologyID == -1) { <div class="CheckBoxItem"> <input type="checkbox" name="option1" id="allTechnology" value="@technologyName.TechnologyID" checked="checked" /> @technologyName.Name </div> } else { <input type="checkbox" name="option2" id="tech" value="@technologyName.TechnologyID" /> @technologyName.Name } } } 

I need to somehow add @technologyName.TechnologyID to id="tech" in order to have at the end

 id="tech_123" 

How can i do this?

Thanks!

+6
source share
1 answer

try this (basically adding brackets around the property):

 <input type="checkbox" name="option2" id="tech_ @(technologyName.TechnologyID)" value="@technologyName.TechnologyID" /> 
+12
source

Source: https://habr.com/ru/post/921488/


All Articles