0

I use a for loop to populate a table:

@using (Html.BeginForm(null, null, FormMethod.Get, new { name = "frm", id = "frm" })) {
  <table id="table1" border="1" style ="width:100%">  
    @for (int i = 1; i < 13; i++)
        {
        <tr>
            <td>
                @(i.ToString()+". Details") 
            </td>
            <td>
                <button type="button" onclick="invisiblize(i)">Show detail @i</button>
            </td>
        </tr>
        }
  </table>

Is it possible to assign IDs for the buttons generated after the above code?

1 Answer 1

2

I'm not sure if you need to assign the ID's after the code runs, but this will allow you to set the ID while the code is running...

@using (Html.BeginForm(null, null, FormMethod.Get, new { name = "frm", id = "frm" })) {
      <table id="table1" border="1" style ="width:100%">  
        @for (int i = 1; i < 13; i++)
            {
            <tr>
                <td>
                    @(i.ToString()+". Details") 
                </td>
                <td>
                    <button id="[email protected]()" type="button" onclick="invisiblize(i)">Show detail @i</button>
                </td>
            </tr>
            }
      </table>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.