0
我正在我的網站上實施反饋。就像現在一樣,用戶會看到一組部分,每部分都包含一組問題。每個問題有5個可能的答案,以單選按鈕的形式出現,每個問題都有相同的可能答案列表。只能選擇1個單選按鈕,而不是每組中的一個
一切都畫我所想要的,但我appearantly頁面上識別它的每一個單選按鈕作爲這將導致僅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來確定哪些屬於一組?
這似乎確實是問題。我已經通過顯式使用html而不是razor語法來生成name屬性來解決此問題。 – 2013-05-10 16:37:50
@JeroenVannevel很高興能幫到你!祝你的項目好運! – eidsonator 2013-05-10 16:39:37