【发布时间】:2015-10-27 11:06:12
【问题描述】:
在我的班级中,我有更多的属性,并且在我提交表单后检查时都具有良好的价值 除了总是为假的布尔值之外,所有变量都很好。 有人能帮我吗? 我的班级:
public class Pilot
{
.....
public bool OwnerOrPart { get; set; }
.....
}
我的模特:
public class IardModel : RepositoryCollection
{
.......
public List<Pilot> Pilot { get; set; }
.....
public IardModel()
{
.....
Pilot = new List<Pilot>();
.....
}
}
控制器:
public ActionResult Aeronef(IardModel model, string id)
{
if (id != "") {
using (var scope = RepositoryContainer.Container.BeginLifetimeScope())
{
var repository = scope.Resolve();
model = repository.SingleById(id);
model.IsEditing = true;
return View(model);
}
}
model.IsEditing = false;
return View(model);
}
以及观点:
@if (Model.Pilot.Count == 0)
{
....
<section class="col col-md-2">
<label class="label-form">(Co)Propriétaire</label>
<label class="checkbox">
<input name="Pilot[0].OwnerOrPart" type="checkbox" class="form-control">
<i></i>
</label>
</section>
}
@foreach (var pilots in Model.Pilot)
{
....
<section class="col col-md-2">
<label class="label-form">(Co)Propriétaire</label>
<label class="checkbox">
<input name="Pilot[@(Model.Pilot.IndexOf(pilots))].OwnerOrPart" type="checkbox" class="form-control" @(pilots.OwnerOrPart ? "checked='checked'" : "")>
<i></i>
</label>
</section>
}
所有变量都很好,除了总是为假的布尔值。 谁能帮帮我
【问题讨论】:
-
我的控制器:
public ActionResult Aeronef(IardModel model, string id) { if (id != "") { using (var scope = RepositoryContainer.Container.BeginLifetimeScope()) { var repository = scope.Resolve<IRepository>(); model = repository.SingleById<IardModel>(id); model.IsEditing = true; return View(model); } } model.IsEditing = false; return View(model); }
标签: c# asp.net-mvc razor