我的模型是:
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);
}
我的观点是:
@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" />
}
我的屏幕是:
我的调试是:
但是,我想使用 RadioButton 做同样的事情:
<input type="radio" id="radio3" value="@item.Option1" name="[@i].Option1 == checked ? true : false" />
我想根据我的列表项设置值 TRUE 或 FALSE。
你能帮助我吗?谢谢!