views:

22

answers:

2

In VS 2010, When you use the "Add View" wizard to create an Edit view with a strongly typed view, such as Models.Person, the template generates all of Person fields for you.

If you use a view model instead, like this:

public class PersonVM
{
   public Person person;
   public List<Team> TeamList = new TeamServices().TeamPickList();
   ...
}

the template wont create all of the fields for Model.person.

Is there a way to make that work?

+1  A: 

Not automatically.

Easiest method is to create a new View, select Team as the view data class, Select 'List' as the view content. Then you could cut and paste the markup generated from this view into the one you have already created.

Clicktricity
Sorry, meant to say I want an Edit view.
PeteShack
+1  A: 

If you use the List template it will normally create a table and iterate over an IEnumerable Model. You can also use one of the helpers and/or custom templates in your CodeTemplates folder:

<% Html.DisplayForModel(); %>

If you need to edit:

<% Html.EditorForModel(); %>

If you're having trouble with the list, maybe start with one of the helpers?

<%: Html.DropDownListFor(model => model.TeamList, new SelectList(Model.TeamList)) %>
Justin Soliz