Question

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.

Was it helpful?

Solution

Please try this

  @(Html.RadioButtonFor(model => model.IndividualSections[count].SectionScores[questionCount].score.pass, true, new {@id=sectionDetail.Title + count.Tostring() }) ))

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top