Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add model value to the 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
                }
              }
          }

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

id="tech_123" 

How I can do it?

Thank you!

like image 355
Friend Avatar asked Jul 27 '12 12:07

Friend


People also ask

Can we modify the attribute value of HTML tag dynamically?

Yes!

Which HTML tags have value attribute?

The value attribute in HTML is used to specify the value of the element with which it is used. It has different meaning for different HTML elements. Usage: It can be used with the following elements: <input>, <button>, <meter>, <li>, <option>, <progress>, and <param>, <output>.

Can you give a div a value?

div elements don't have a . value property that would get submitted to the backend; use an input element for that.


1 Answers

try this (basically adding parenthesis around the property):

<input type="checkbox" name="option2" id="tech_
@(technologyName.TechnologyID)"  value="@technologyName.TechnologyID" />
like image 106
jim tollan Avatar answered Oct 20 '22 21:10

jim tollan