Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在模型中填充数组以进行回发_C#_Asp.net_Arrays_Asp.net Mvc_Model - Fatal编程技术网

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; }
}