2

I am generating radiobuttonfor dynamically. My code runs as,

@{int questionCount = 0;
 }
@{foreach (SectionDetail sectionDetail in section.SectionDetails)
 {                              
    <table>
        <tr>
            <td>
                @Html.Label(sectionDetail.Title)
            </td>
            @{count = 0;
            }
            @foreach (SectionScore sectionScore in Model.IndividualSections)
            {

                <td class="ColSupplier">
                    @Html.RadioButtonFor(model => model.IndividualSections[count].SectionScores[questionCount].score.pass, true)Pass
                    @Html.RadioButtonFor(model => model.IndividualSections[count].SectionScores[questionCount].score.pass, false)Fail
                </td>
               count++;
            }
        </tr>
    </table>

    questionCount++;
  }

Here some radio buttons are having the same name. So I am unable to get the exact value. How to give different names for these radio buttons. Please help me in sorting this out.

Ashiq A N
  • 776
  • 1
  • 8
  • 16

2 Answers2

1

Please try this

  @(Html.RadioButtonFor(model => model.IndividualSections[count].SectionScores[questionCount].score.pass, true, new {@id=sectionDetail.Title + count.Tostring() }) ))
  • this might not work because the radio button grouping is based on the name. The model binded will act as a name. So the same name is binded in two or more rows. so the grouping falls in one or more rows. I need the grouping to be restricted in a single row. – Ashiq A N Jan 19 '12 at 04:18
0

You can use HtmlAttributes to define unique IDs.

@Html.RadioButtonFor(model => model.IndividualSections[count].SectionScores[questionCount].score.pass, true, new { id= count.ToString()});

Hope this helps you.

Anwar
  • 4,470
  • 4
  • 24
  • 30