【问题标题】:radio button binding in IList <model > mvc viewIList <model> mvc 视图中的单选按钮绑定
【发布时间】:2013-09-04 12:15:12
【问题描述】:

我的视图是这样的,如何在 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" />
}

我只想为每一行检查 1 个单选按钮。并且从数据将传递给我的控制器。我的控制器是这样的。

[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..

提前谢谢...

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4


【解决方案1】:

试试这个

 @foreach (var item in Model)
                            {


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


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

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

option1 和 option2 是选项。并将在模型中定义

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2011-01-18
    相关资源
    最近更新 更多