一切正常,但我需要绑定许多可能的“Regs”。Bind(Prefix = "Regs[0]",...一直到Bind(Prefix = "Regs[n]",...某个自然数 n。那么当foreach需要在传递给ActionResult索引的内容中时,我如何在这种情况下进行迭代?
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index([Bind(Prefix = "Main", Include = "AlterationForseenChanges,AlterationGrowthDecline,DescriptionEcozone,DescriptionEcoregion,DescriptionEcodistrict,DescriptionPreviousDB")] SESData sESData
,[Bind(Prefix = "Regs[0]", Include = "RegulationName,RegulationDescription,RegulationURL")] SESRegulationsList sESRegulationList)
{
if (ModelState.IsValid)
{
db.SESData.Add(sESData);
db.SESRegulationList.Add(sESRegulationList);
db.SaveChanges();
return RedirectToAction("Report", new { id = sESData.id});
}
return View(sESData);
}
这是基本的视图模型
public class SESDataViewModel
{
public SESData Main { get; set; }
public List<SESRegulationsList> Regs { get; set; }
}
该视图只有不确定数量的编辑器,与这些完全一样
@Html.EditorFor(m => m.Regs[0].RegulationDescription)
@Html.EditorFor(m => m.Regs[1].RegulationDescription)...
@Html.EditorFor(m => m.Regs[n].RegulationDescription)
相关分类