我正在我的网站上实施反馈。就像现在一样,向用户显示了一组部分,每个部分包含一组问题。每个问题都有 5 个单选按钮形式的可能答案,每个问题都有相同的可能答案列表。
一切都按照我的意愿绘制,但显然我的页面将其上的每个单选按钮识别为同一问题的一部分,这导致整个页面上只有 1 个可选单选按钮。
这是我用来生成页面的代码:
<div class="centered feedbackwrapper ">
@using (Html.BeginForm("SaveFeedback", "Leertraject")) {
<h3>Feedback voor leertraject @Model.LeertrajectCode</h3>
foreach (var section in Model.Sections) {
<div class="feedbackonderdeel well">
<h4>@section.Name</h4>
@foreach (var question in section.Questions) {
<div class="feedback ">
<p class="feedbackvraag">@question.Question
<br />
@{
var choices = (IList<FeedbackChoiceViewModel>) Session["Choices"];
}
@foreach (var choice in choices) {
<span class="feedbackkeuze">
@Html.RadioButtonFor(x => choice.ChoiceID, @choice.ChoiceID, new {@id = @question.QuestionID})
@choice.Choice
</span>
}
</p>
</div>
}
</div>
}
<input type="submit" class="btn btn-info" value="@Strings.SaveFeedback" />
}
</div>
生成的视图:
以及生成的源代码:
<div class="feedback ">
<p class="feedbackvraag">Vraag 1
<br />
<span class="feedbackkeuze">
<input checked="checked" id="1" name="keuze.KeuzeID" type="radio" value="1" />
OV
</span>
<span class="feedbackkeuze">
<input checked="checked" id="1" name="keuze.KeuzeID" type="radio" value="2" />
V
</span>
<span class="feedbackkeuze">
<input checked="checked" id="1" name="keuze.KeuzeID" type="radio" value="3" />
G
</span>
<span class="feedbackkeuze">
<input checked="checked" id="1" name="keuze.KeuzeID" type="radio" value="4" />
ZG
</span>
<span class="feedbackkeuze">
<input checked="checked" id="1" name="keuze.KeuzeID" type="radio" value="5" />
NVT
</span>
</p>
</div>
<div class="feedback ">
<p class="feedbackvraag">Vraag 2
<br />
<span class="feedbackkeuze">
<input checked="checked" id="2" name="keuze.KeuzeID" type="radio" value="1" />
OV
</span>
<span class="feedbackkeuze">
<input checked="checked" id="2" name="keuze.KeuzeID" type="radio" value="2" />
V
</span>
<span class="feedbackkeuze">
<input checked="checked" id="2" name="keuze.KeuzeID" type="radio" value="3" />
G
</span>
<span class="feedbackkeuze">
<input checked="checked" id="2" name="keuze.KeuzeID" type="radio" value="4" />
ZG
</span>
<span class="feedbackkeuze">
<input checked="checked" id="2" name="keuze.KeuzeID" type="radio" value="5" />
NVT
</span>
</p>
</div>
考虑到问题的每组答案都具有相同的 ID,我希望它们被分组,而不是页面上的每个单选按钮。为什么它将每个单选按钮视为一个组,而不是查看 ID 来确定哪些属于一起?