如何在模型的侧面填充数组以进行回发

我有一个包含Milestone列表的模型,我希望在网页中使用给定的一组文本框填充(在模型内)列表。

 public class Project { public string ProjectNumber { get; set; } public IList Parameters; public IList MilestoneList = new List(); } 

在我的Html.BeginForm("Edit", "Home", FormMethod.Post, new { Project = Model }))我有以下TextBox。

 @for (int i = 0; i < Model.MilestoneList.Count; i++) { @Html.TextBoxFor(model=>model.MilestoneList[i].Value) } 

我的控制器在milestonelist下面的问题在模型Project中始终为null

 [HttpPost] public ActionResult Edit(Project project) { helper.CreateProject(project, System.Web.HttpContext.Current.User.Identity.Name); return View(); } 

那么我应该如何编程,以便模型中的列表将通过TextBoxes填充?

您在模型中使用字段,而不是属性,因此DefaultModelBinder无法设置该值。 将模型更改为

 public class Project { public string ProjectNumber { get; set; } public IList Parameters { get; set; } public IList MilestoneList { get; set; } } 

并在控制器中初始化集合。