ASP.NET MVC 5組單選按鈕我正在開始我的第一個ASP.NET MVC項目,所以我有一個簡單的問題。我有以下代碼:foreach(var question in Model.GeneralQuestions){
<div class = "well">
<h3>
<strong>@question.QuestionString</strong>
</h3>
@foreach (var answer in question.PossibleAnswers)
{
@Html.RadioButtonFor(model => question.QuestionString, answer.Answer)
@Html.Label(answer.Answer)
<br />
}
</div>}Model.GeneralQuestions中的所有問題都是唯一的,因此單選按鈕應(yīng)按名稱屬性分組(對于每個問題,一組單選按鈕)。但是這段代碼只生成一個組,所以當(dāng)我回答第二個問題時,首先會取消選擇。我需要改變什么?編輯我的模型看起來像:public class StudentViewModel{
public Student Student { get; set; }
public List<Question> GeneralQuestions { get; set; }
public List<SubjectQuestions> SubjectQuestions { get; set; }}public class Student{
public int StudentID { get; set; }
public string Index { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public virtual ICollection<Subject> Subjects { get; set; }}public class Question{
public int QuestionID { get; set; }
public string QuestionString { get; set; }
public bool IsAssociatedWithSubject { get; set; }
public virtual ICollection<PossibleAnswer> PossibleAnswers { get; set; }
public virtual ICollection<Results> Results { get; set; }}public class SubjectQuestions{
public Subject Subject { get; set; }
public List<Question> Questions { get; set; }}public class Results{
public int ResultsID { get; set; }
public int QuestionID { get; set; }
public int? SubjectID { get; set; }
public int PossibleAnswerID { get; set; }
public virtual Question Question { get; set; }
public virtual PossibleAnswer PossibleAnswer { get; set; }
public virtual Subject Subject { get; set; }}在StudentViewModel的一個實例中,我保存了一個學(xué)生和他應(yīng)該回答的所有問題(一般和他正在研究的科目相關(guān))并將其傳遞給查看。在視圖中,我將所有問題都以單一形式提出,它們都是無線電的類型。那么,任何人都可以幫我分組單選按鈕并正確回發(fā)此表單嗎?
- 2 回答
- 0 關(guān)注
- 551 瀏覽
添加回答
舉報
0/150
提交
取消