I am trying to learn ASP.NET MVC. Currently I want to render a create page of a model, which has reference to another model, and make user select the other model from drop down list. To be more specific, here is the code for Category
model
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
And here is the code of Food
model
public class Food
{
public int Id { get; set; }
public string Name { get; set; }
public Category Category { get; set; }
}
Consider I have an in memory list of categories called categories
and I want to make sure that when I send create view to user with return View();
in HomeController
's Create
method he gets not only the name to choose but also the drop down of categories
. Also consider that in near future I want to generate the tables of database according to these classes (Entity Frameworks code first approach) so adding properties to the classes doesn't seem like a good idea.
How can I do that?