我有一个项目模型和一个任务模型。
在我的控制器中说我有
public ActionResult Create()
{
Project p = new Project();
Task t1=new Task();
Task t2=new Task();
Task t3=new Task();
p.tasks.Add(t1);
p.tasks.Add(t2);
p.tasks.Add(t3);
}
在我的项目强类型视图中,我有
Html.EditorForModel()
我怎样才能让它显示项目的字段以及每个任务的字段?
请帮忙!
--------为澄清而添加
public ActionResult Create(Guid LicenseId)
{
License license;
if (!User.IsInRole("admin"))
license = _service.GetContributor(User.Identity.Name).Licenses.Single(l => l.Id == LicenseId);
else
license = _service.GetLicenseById(LicenseId);
if (license == null)
return RedirectToAction("Index", "Home");
IncomeDeclaration i = new IncomeDeclaration();
foreach(var ecoActLicense in license.EconomicActivitiyLicenses)
{
EconomicActivityIncomeDeclaration ecoActIncDec = new EconomicActivityIncomeDeclaration();
ecoActIncDec.ActivityTax = 20;
ecoActIncDec.EconomicActivityId = ecoActLicense.EconomicActivityId;
i.EconomicActivityIncomeDeclarations.Add(ecoActIncDec);
}
return View(i);
}
这段代码是我首先将 EconomicActivityIncomeDeclarations 与 IncomeDeclaration 关联起来的地方。
在视图中,对于 IncomeDeclaration 的强类型,我只是有
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>IncomeDeclaration</legend>
@Html.EditorForModel()
@Html.EditorFor(m =>m.EconomicActivityIncomeDeclarations)
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}