我正在为自己创建一个项目经理类型的应用程序作为学习体验。我正在使用 ASP.NET MVC3 并且将使用 jQuery 来更进一步。现在我已经使用 Ninject/Moq 创建了模型和一些模拟存储库。
模型:
public class Project
{
    public int ProjectID { get; set; }
    public string ProjectName { get; set; }
    public string Description { get; set; }
    public string[] AssignedEmployees { get; set; }
    public string[] ProjectGoals { get; set; }
    public DateTime ProjectStart { get; set; }
    public DateTime ProjectDeadLine { get; set; }
    public string Notes { get; set; }
}
模拟存储库:
Mock<IProjectRepository> projectMock = new Mock<IProjectRepository>();
        projectMock.Setup(m => m.Projects).Returns(new List<Project> 
        {
            new Project {ProjectID = 1234, ProjectName = "Email redesign", Description = "New email", AssignedEmployees = new string[] {"Ian", "Danny", "Mikey"}},
            new Project {ProjectID = 4321, ProjectName = "Update Cart", Description = "Make cart smoother function better"},
            new Project {ProjectID = 4567, ProjectName = "New social widget", Description = "More social media buttons"}
        }.AsQueryable());
        ninjectKernel.Bind<IProjectRepository>().ToConstant(projectMock.Object);
看法:
@foreach  (var p in Model){
<div class='project'>
    <h3>@p.ProjectName</h3>
    <p>@p.Description</p>
    <ul class='assigned-employees'>
        <li class="employee">
        @p.AssignedEmployees
        </li>
    </ul>
</div>
}
问题在于,在 AssignedEmployees 数组的视图中呈现的所有内容都是System.String[]. 我试过了.ToString,.ToArray我试过做一个foreach循环来循环遍历数组中的每个项目,以将它们分别打印到一个单独的 li 中。
如何让它打印数组中的所有名称?使用数组是否是最好的解决方案?我希望任何使用该应用程序的人都可以为项目分配任意数量的员工,这就是为什么我认为数组可能是最好的。