I'm trying to combine two views in one model. But I cannot get it too work!
Can you help me?
Models:
public class Player
{
public int playerID { get; set; }
[Required]
[Display(Name = "Spelernaam:")]
public String playerName { get; set; }
[Display(Name = "Team:")]
public int teamID { get; set; }
public virtual Team Team { get; set; }
[Required]
[Display(Name = "Waarde:")]
public int playerValue { get; set; }
}
public class Team
{
public int teamID { get; set; }
[Required]
[Display(Name = "Teamnaam:")]
public String teamName { get; set; }
[Required]
[Display(Name = "Teamwaarde:")]
[Range(0, 100, ErrorMessage = "Waarde moet tussen de 0 en de 100 liggen")]
public int teamValue { get; set; }
[Required]
[Display(Name = "Teambudget:")]
[Range(0, 100000000, ErrorMessage = "Waarde moet tussen de 0 en de 100000000 liggen")]
public int teamBudget { get; set; }
[DefaultValue(0)]
public int gamePoints { get; set; }
public virtual ICollection<Player> Player { get; set; }
}
I'm trying to get a list of players in a detail page of a team (scaffold).
I have already tried to make a viewmodel and it looks like this:
public class PlayersPerTeam
{
public Team Team { get; set; }
public Player Player { get; set; }
}
But i think the controller is the problem
Controller:
//
// GET: /Team/Details/5
public ActionResult Details(int id = 0)
{
Team team = db.Teams.Find(id);
if (team == null)
{
return HttpNotFound();
}
return View(team);
}
I hope you can help me with this! thanks alot!
Error message:
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Team_B041141ED3453289BD09E3CAC14C091B831E03C09FDA76FF2D783BDDCE179358', but this dictionary requires a model item of type 'HerkansingsOpdracht.Models.PlayersPerTeam'.