Reputation: 63
I have these models:
public class Condominium
{
public int CondominiumID { get; set; }
public int BatchID { get; set; }
public string Name { get; set; }
public bool LiveInCondominium { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public Batch Batch { get; set; }
public List<Employee> Employees { get; set; }
}
public class Employee
{
public int EmployeeID { get; set; }
public int CityID { get; set; }
public string UserID { get; set; }
public Condominium CondominiumID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string ZipCode { get; set; }
public string Contact { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public City City { get; set; }
public Condominium Condominium { get; set; }
}
I need to create Employee
objects dynamically and put them into a list and when I make a post request the object Condominium
contains a list with Employee
objects. I don't have any idea how I can make the view for this.
Upvotes: 2
Views: 845
Reputation: 1634
I suggest that you build View models for each view, in this case you would build a model that contains a property that holds a list of employees. You would then simple fill the model and return it to the view.
Here is some pseudo code:
Controller
public ActionResult Index()
{
var viewModel = new ViewModel()
{
Employees = BuildListOfEmployees() // Method that gets/builds a list of employees, expected return type List<Employee>
};
return View(viewModel);
}
class ViewModel
{
public List<Employee> Employees { get; set; }
}
View
@model YourNamespace.ViewModel
<ul>
@foreach (var employee in Model)
{
<li>employee.Name</li>
}
</ul>
Upvotes: 2
Reputation: 633
Typically this information is stored in a database and you just pass the IDs as URL parameters. The HTTP request handler will take the parameter(s) and look up the information it needs from the database.
Your object structure looks pretty flat so they would translate easily to Tables in a relational database.
Upvotes: -1