2013-09-01 44 views
0

如何綁定mvc中的單選按鈕,因爲我的視圖是這樣的?IList中的單選按鈕綁定<model > mvc視圖

@model IList<CMM.Models.Question> 
@using (Html.BeginForm("Index", "Ques", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-3" })) 
{ 

@foreach (var item in Model) 
         { 
@Html.RadioButtonFor(item.QuestionId,item.QuestionId,item)//error in this line 
@Html.RadioButtonFor(item.QuestionId,item.QuestionId,item)//error in this line 
} 
<input type="submit" value="Save" /> 
} 

我只想要爲每一行檢查一個單選按鈕。並從數據傳遞給我的controller.My控制器是這樣的。

[HttpPost] 
     public ActionResult Index(IList<Question> sq) 
     {   

      return View(); 
     } 

我該如何顯示單選按鈕。我想在無線電中使用3個功能。

1)different id's 
2)different values 
3)javascript func call onclick of radio button.. 

在此先感謝...

+0

而不是「RadioButtonFor」嘗試「RadioButton」來代替。 –

+0

你可以展示你的問題模型嗎? –

+0

看看這裏它覆蓋你的情況: http://stackoverflow.com/a/6640157/2932724 –

回答

0

試試這個

@foreach (var item in Model) 
          { 


    @Html.RadioButtonFor(item => item .QuestionId, item.option1) 


    @Html.RadioButtonFor(item => item .QuestionId, item.option2) 

    } 
    <input type="submit" value="Save" /> 
    } 

選項1和選項是選項。並將在模型中定義

相關問題