C# 如何在模型中填充数组以进行回发
我有一个模型,其中包含一个C# 如何在模型中填充数组以进行回发,c#,asp.net,arrays,asp.net-mvc,model,C#,Asp.net,Arrays,Asp.net Mvc,Model,我有一个模型,其中包含一个里程碑列表,我希望该列表(在模型内部)在网页中填充一组给定的文本框 public class Project { public string ProjectNumber { get; set; } public IList<Parameter> Parameters; public IList<Milestone> MilestoneList = new List<Milestone>(); } 在模型项目中
里程碑列表
,我希望该列表(在模型内部)在网页中填充一组给定的文本框
public class Project
{
public string ProjectNumber { get; set; }
public IList<Parameter> Parameters;
public IList<Milestone> MilestoneList = new List<Milestone>();
}
在模型项目中,milestonelist下面的控制器中的问题总是null
[HttpPost]
public ActionResult Edit(Project project)
{
helper.CreateProject(project, System.Web.HttpContext.Current.User.Identity.Name);
return View();
}
那么,我应该如何编程,以便通过文本框填充模型中的列表呢?您使用的是模型中的字段,而不是属性,因此
DefaultModelBinder
无法设置该值。将您的模型更改为
public class Project
{
public string ProjectNumber { get; set; }
public IList<Parameter> Parameters { get; set; }
public IList<Milestone> MilestoneList { get; set; }
}
公共类项目
{
公共字符串ProjectNumber{get;set;}
公共IList参数{get;set;}
公共IList MilestoneList{get;set;}
}
并在控制器中初始化集合
public class Project
{
public string ProjectNumber { get; set; }
public IList<Parameter> Parameters { get; set; }
public IList<Milestone> MilestoneList { get; set; }
}