title: ASP.NET MVC InvalidOperationException was unhandled by user code while following book example
body: <pre><code>namespace SportsStore.Domain.Entities
  {
      public class Product
      {
          [HiddenInput(DisplayValue = false)]
          public int ProductID { get; set; }
  
          //[Required(ErrorMessage = "Please enter a product name")]
          public string Name { get; set; }
          [DataType(DataType.MultilineText)]
  
          //[Required(ErrorMessage ="Please enter a description")]
          public string Description { get; set; }
  
          //[Required]
          //[Range(0.01, double.MaxValue, ErrorMessage = "Please enter a positive price")]
          public decimal Price { get; set; }
  
          //[Required(ErrorMessage = "Please specify a category")]
          public string Category { get; set; }
      }
  }
  </code></pre>
  
  <p>This is the entity definition, and below is action from a controller.</p>
  
  <pre><code>    public ViewResult List(string category, int page = 1)
      {
          ProductsListViewModel model = new ProductsListViewModel
          {
              Products = repository.Products.Where(p =&gt; category == null || p.Category == category).OrderBy(p =&gt; p.ProductID).Skip((page - 1) * PageSize).Take(PageSize),
  
              PagingInfo = new PagingInfo
              {
                  CurrentPage = page,
                  ItemsPerPage = PageSize,
                  TotalItems = category == null ? repository.Products.Count() : repository.Products.Where(e =&gt; e.Category == category).Count()
              },
  
              CurrentCategory = category
          };
  
          return View(model);
      }
  </code></pre>
  
  <p>I get InvalidOperationException complain from Visual Studio when I uncomment [Required...] in Product class. But it works fine with as it is(commented).</p>
  
  <p>I tried to fix it and googled it but can't solve this problem by myself.</p>
  
  <p>Thanks in advance.</p>