2012-01-18 5 views
2

私はradiobuttonforを動的に生成しています。 私のコードはここ動的に生成されるラジオボタンの名前を与える方法

@{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++; 
    } 

、として実行され、いくつかのラジオボタンは、同じ名前を持つています。だから私は正確な値を得ることができません。これらのラジオボタンに異なる名前を付ける方法。これを整理するのを手伝ってください。

答えて

1

この

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

ラジオボタンのグループ化が名前に基づいているため、これは機能しない可能性があります。バインドされたモデルは名前として機能します。したがって、同じ名前が2つ以上の行にバインドされています。グループ化は1つ以上の行に分類されます。グループ化を1行に制限する必要があります。 –

0

HtmlAttributesを使用して一意のIDを定義できます。

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

希望します。

+0

私は行で同じになるように名前を必要としてみてください。 –

関連する問題