title: Model bound complex types must not be abstract or value types and must have a parameterless constructor
body: <p>I have the following problem, I created an application to add game categories and the games themselves to the database. I created a relationship and unfortunately when I add to the database I get an error.</p>
  
  <blockquote>
    <p>Model bound complex types must not be abstract or value types and must
    have a parameterless constructor.</p>
  </blockquote>
  
  <p>Game Category Model</p>
  
  <pre><code>using System.Collections.Generic;
  
  namespace relationship.Models
  {
      public class GameCategory
      {
          public int Id { get; set; }
          public string Name { get; set; }
  
          public ICollection&lt;Game&gt; Game { get; set; }
      }
  }
  </code></pre>
  
  <p>Game Model</p>
  
  <pre><code>namespace relationship.Models
  {
      public class Game
      {
          public int GameId { get; set; }
          public string Name { get; set; }
  
          public GameCategory Category { get; set; }
          public int CategoryId { get; set; }
      }
  }
  </code></pre>
  
  <p>ViewModel</p>
  
  <pre><code>using relationship.Models;
  using System.ComponentModel.DataAnnotations;
  using System.Collections.Generic;
  using Microsoft.AspNetCore.Mvc.Rendering;
  namespace relationship.ViewModels
  {
      public class AddGameViewModel
      {     
          [Required]
          public string GameName { get; set; }
          public int CategoryID { get; set; }
  
          public List&lt;SelectListItem&gt; Categories { get; set; }
  
          public AddGameViewModel(IEnumerable&lt;GameCategory&gt; categories)
          {
              Categories = new List&lt;SelectListItem&gt;();
              foreach (var catData in categories)
              {
                  Categories.Add(new SelectListItem { Text = catData.Name.ToString(), Value = catData.Id.ToString() });
              }
              return;
          }
      }
  }
  </code></pre>
  
  <p>GameRepository</p>
  
  <pre><code>using System.Collections.Generic;
  using System.Linq;
  
  namespace relationship.Models
  {
      public class GameRepository : IGameRepository
      {
          private readonly AppDbContext appDbContext;
          public GameRepository(AppDbContext dbContext)
          {
              appDbContext = dbContext;
          }
  
          public void AddGame(Game game)
          {
              appDbContext.Games.Add(game);
              appDbContext.SaveChanges();
          }
  
          public IEnumerable&lt;Game&gt; Games()
          {
              return appDbContext.Games.ToList();
          }
      }
  }
  </code></pre>
  
  <p>and last is GameController</p>
  
  <pre><code>using Microsoft.AspNetCore.Mvc;
  using relationship.Models;
  using relationship.ViewModels;
  
  namespace relationship.Controllers
  {
      public class GameController : Controller
      {
          private readonly IGameRepository gameRepository;
          private readonly ICategoryRepository categoryRepository;
  
          public GameController(IGameRepository gameRepo, ICategoryRepository catRepo)
          {
              gameRepository = gameRepo;
              categoryRepository = catRepo;
          }
  
          public IActionResult Index()
          {
              return View();
          }
  
          [HttpGet]
          public IActionResult Add()
          {
              var addGameViewModel = new AddGameViewModel(categoryRepository.GameCategory());
              return View(addGameViewModel);
          }
  
          [HttpPost]
          public IActionResult Add(AddGameViewModel addGameViewModel)
          {
              if (ModelState.IsValid)
              {
                  GameCategory gameCategory = categoryRepository.GetDetails(addGameViewModel.CategoryID);
  
                  if(gameCategory == null)
                  {
                      return NotFound();
                  }
  
                  Game game = new Game
                  {
                      Name = addGameViewModel.GameName,
                      Category = gameCategory
                  };
  
                  gameRepository.AddGame(game);
                  return RedirectToAction("Index");
              }
              return View(addGameViewModel);
          }
      }
  }
  </code></pre>
  
  <p>I don't have any idea what is wrong.</p>
  
  <p>My error screen</p>
  
  <p><a href="https://i.stack.imgur.com/PTe81.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PTe81.png" alt="enter image description here"></a></p>