C# 如何使用radioButton在Aspnet mvc4中创建动态列表?

C# 如何使用radioButton在Aspnet mvc4中创建动态列表?,c#,asp-net-mvc-1,C#,Asp Net Mvc 1,我的模型是: namespace MvcApplication5.Models { public class DepartmentModelClass { public int Id { get; set; } public string Text1 { get; set; } public string Text2 { get; set; } public bool? Option1 { get; set; }

我的模型是:

namespace MvcApplication5.Models
{
    public class DepartmentModelClass
    {
        public int Id { get; set; }
        public string Text1 { get; set; }
        public string Text2 { get; set; }
        public bool? Option1 { get; set; }
        public bool Option2 { get; set; }
    }
}
我的控制器是:

 public ActionResult Index()
        {
            List<DepartmentModelClass> list = new List<DepartmentModelClass>();
            list.Add(new DepartmentModelClass { Id = 1, Text1 = "test1", Text2 = "test2", Option1 = false, Option2 = false });
            list.Add(new DepartmentModelClass { Id = 2, Text1 = "test3", Text2 = "test4", Option1 = false, Option2 = false });
            list.Add(new DepartmentModelClass { Id = 3, Text1 = "test5", Text2 = "test6", Option1 = false, Option2 = false });

            return View(list);
        }
public ActionResult Index()
{
列表=新列表();
添加(新部门模型类{Id=1,Text1=“test1”,Text2=“test2”,Option1=false,Option2=false});
添加(新的部门模型类{Id=2,Text1=“test3”,Text2=“test4”,Option1=false,Option2=false});
添加(新的部门模型类{Id=3,Text1=“test5”,Text2=“test6”,Option1=false,Option2=false});
返回视图(列表);
}
我的看法是:

@model IEnumerable<MvcApplication5.Models.DepartmentModelClass>

@{
    Layout = null;
}

@using (Html.BeginForm("Index", "Employee", FormMethod.Post, new { id = "idForm" })) {
    int i = 0;
    foreach (var item in Model) {
            <div class="row">
                <div class="form-group">
                    <span>@i:</span>
                    <input type="text" id="idtext1" value=@item.Text1 name="[@i].Text1" />
                    <input type="text" id="idtext2" value=@item.Text2 name="[@i].Text2" />
                    <hr />
                </div>
            </div>
        i += 1;
    }

    <input type="submit" value="Submit" />
}
@model IEnumerable
@{
布局=空;
}
@使用(Html.BeginForm(“Index”,“Employee”,FormMethod.Post,new{id=“idForm”})){
int i=0;
foreach(模型中的var项目){
@一:

i+=1; } }
我的屏幕是:

我的调试是:

但是,我想用RadioButton做同样的事情:

<input type="radio" id="radio3" value="@item.Option1" name="[@i].Option1 == checked ? true : false" />

我想根据我的列表项设置值TRUE或FALSE


你能帮我吗?谢谢

请您进一步说明

如果要根据选项1值显示单选按钮,则代码如下

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "idForm" }))
    {
        int i = 0;
        foreach (var item in Model)
        {
            <div class="row">
                <div class="form-group">
                    <span>@i:</span>
                    @if (item.Option1 == true)
                    {
                        <input type="radio" id="radio_@i" value="@item.Option1" name="radio_@i" checked="checked" />
                        <input type="text" id="idtext1" value=@item.Text1 name="[@i].Text1" />
                        <input type="text" id="idtext2" value=@item.Text2 name="[@i].Text2" />
                    }
                    else
                    {
                        <input type="radio" id="radio_@i" value="@item.Option1" name="radio_@i" />
                        <input type="text" id="idtext1" value=@item.Text1 name="[@i].Text1" disabled="disabled" />
                        <input type="text" id="idtext2" value=@item.Text2 name="[@i].Text2" disabled="disabled" />
                    }


                    <hr />
                </div>
            </div>
            i += 1;
        }

        <input type="submit" value="Submit" />
    }
@使用(Html.BeginForm(“Index”,“Home”,FormMethod.Post,new{id=“idForm”}))
{
int i=0;
foreach(模型中的var项目)
{
@一:
@如果(item.Option1==true)
{
}
其他的
{
}

i+=1; } }
我想在动态列表中设置布尔值。我正在尝试制作一个动态表单D