2011-03-18 32 views
2

我正在嘗試爲我的問題創建RadioButtonFor或CheckBoxFor。我創造了這個模式:RadioButtonFor在asp.net mvc只創建一個單選按鈕

public class Question 
    { 
     public int ID { get; set; } 
     public string Question1 { get; set; } 
    } 
    public class Answer 
    { 
     public int ID { get; set; } 
     public string Answer1 { get; set; } 
     public int QId { get; set; } 
    } 
    public class AnModelView 
    { 
     public Answer Answers { get; set; } 
     public IQueryable<Question> Questions { get; set; } 
    } 

在我看來,我想這一點:

<%:Html.RadioButtonFor(model => model.Answers.QId, new SelectList(Model.Questions.Select(qu => new RadioButtonList { DataValueField = qu.ID.ToString(), DataTextField = qu.Question1 }), "Value", "Text"))%>

但產量只有一個單選按鈕。我如何獲得多個單選按鈕 - 每個答案都有一個

+0

你可以使用radioibuttonlist助手從這裏:http://awesome.codeplex.com – Omu 2011-05-20 17:21:48

回答

1

您需要一個單選按鈕列表,而不是單個按鈕。看看這個問題重新:Html.RadioButtonListFor ... Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?

+0

我很驚訝爲什麼所有這一切,有沒有另一種解決方案我的問題 – Abdalmohaymen 2011-03-18 09:34:04

+0

你可以在一個循環內創建你的按鈕... – 2011-03-18 12:16:59

+0

徵收確定我需要這個,但如何綁定模型=> model.Answers.QId與選擇值 – Abdalmohaymen 2011-03-18 18:39:43

相關問題