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

라디오 버튼 그룹이 이름을 기반으로하기 때문에이 방법이 작동하지 않을 수 있습니다. 바인드 된 모델은 이름의 역할을합니다. 그래서 같은 이름이 둘 이상의 행에 묶입니다. 따라서 그룹화는 하나 이상의 행에 속합니다. 그룹화를 한 줄로 제한해야합니다. –

0

HtmlAttributes를 사용하여 고유 ID를 정의 할 수 있습니다.

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

희망이 도움이 될 것입니다.

+0

내가 행에서 동일하게 이름이 필요 보시기 바랍니다. –

관련 문제