I am creating a Project Manager sort of app for self as a learning experience. I am using ASP.NET MVC3 and will be using jQuery to as well further down the line. For now I have created the models and some mock repositories using Ninject/Moq.
Model:
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 repository:
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);
View:
@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>
}
The problem is that all that is rendered in the view for the AssignedEmployees array is System.String[]. I have tried .ToString, .ToArray and I have tried making a foreach loop to loop through each item in the array to print them each to a separate li.
How can I get it to print all the names in the array? Is using an array for this even the best solution? I would like so that anyone using the app can assign as many employees as they want to the project, that's why I thought an array might be best.