Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何为动态生成的RadioButton命名_Asp.net Mvc 3_Radiobuttonfor - Fatal编程技术网

Asp.net mvc 3 如何为动态生成的RadioButton命名

Asp.net mvc 3 如何为动态生成的RadioButton命名,asp.net-mvc-3,radiobuttonfor,Asp.net Mvc 3,Radiobuttonfor,我正在动态生成RadioButton。 我的代码运行为 @{int questionCount = 0; } @{foreach (SectionDetail sectionDetail in section.SectionDetails) { <table> <tr> <td> @Html.Label(section

我正在动态生成RadioButton。 我的代码运行为

@{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++;
  }
@{int questionCount=0;
}
@{foreach(section.SectionDetails中的SectionDetails)
{                              
@Html.Label(sectionDetail.Title)
@{count=0;
}
@foreach(模型中的SectionScore SectionScore.IndividualSections)
{
@Html.RadioButton(model=>model.IndividualSections[count]。SectionScores[questionCount]。score.pass,true)pass
@Html.RadioButton(model=>model.IndividualSections[count]。SectionScores[questionCount]。score.pass,false)失败
计数++;
}
问题计数++;
}

这里有些单选按钮具有相同的名称。因此我无法获得确切的值。如何为这些单选按钮指定不同的名称。请帮助我进行分类。

您可以使用HtmlAttributes定义唯一的ID

@Html.RadioButtonFor(model => model.IndividualSections[count].SectionScores[questionCount].score.pass, true, new { id= count.ToString()});
希望这对您有所帮助。

请尝试一下

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

这可能不起作用,因为单选按钮分组是基于名称的。绑定的模型将用作名称。因此,相同的名称绑定在两行或多行中。因此,该分组属于一行或多行。我需要将分组限制在一行中。我需要名称在一行中相同。