title: ASP.NET MVC Generated views not working properly
body: <p>I have strange error. 
  I made database using SQL Server Management Studio. All Primary Keys, Foreign Keys, Unique set and working. </p>
  
  <p>I imported database into mvc project and generated models, controllers, and views all as stands in this tutorial: <a href="http://www.asp.net/mvc/tutorials/mvc-5/database-first-development/setting-up-database" rel="nofollow">click</a> </p>
  
  <p>But for unknown reason build in validation works only for foreign keys! Even though that all other validation rules were scaffold-ed by Visual Studio. </p>
  
  <p>Don't know what code I should provide so please free to ask and I will update my question.</p>
  
  <p>eg: Create User:</p>
  
  <pre><code>@model magazyn.Models.User
  
  @{
      ViewBag.Title = "Create";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  
  @using (Html.BeginForm()) 
  {
      @Html.AntiForgeryToken()
  
  &lt;div class="form-horizontal"&gt;
      &lt;h4&gt;User&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true)
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.EmployeeNo, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.EmployeeNo)
              @Html.ValidationMessageFor(model =&gt; model.EmployeeNo)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Name, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Name)
              @Html.ValidationMessageFor(model =&gt; model.Name)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Surname, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Surname)
              @Html.ValidationMessageFor(model =&gt; model.Surname)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.ContactInfo, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.ContactInfo)
              @Html.ValidationMessageFor(model =&gt; model.ContactInfo)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.RoleId, "RoleId", new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("RoleId", String.Empty)
              @Html.ValidationMessageFor(model =&gt; model.RoleId)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>        public ActionResult Create()
      {
          ViewBag.RoleId = new SelectList(db.Roles, "Id", "RoleName");
          return View();
      }
      [HttpPost]
      [ValidateAntiForgeryToken]
      [UserEditAuth]
      public ActionResult Create([Bind(Include="Id,EmployeeNo,Name,Surname,ContactInfo,RoleId")] User user)
      {
          if (ModelState.IsValid)
          {
              db.Users.Add(user);
              db.SaveChanges();
              return RedirectToAction("Index");
          }
          ViewBag.RoleId = new SelectList(db.Roles, "Id", "RoleName", user.RoleId);
          return View(user);
      }
  </code></pre>
  
  <p>and user entity (generated by entityFramework):</p>
  
  <pre><code>public partial class User
  {
      public User()
      {
          this.DeviceUsages = new HashSet&lt;DeviceUsage&gt;();
      }
  
      public int Id { get; set; }
      public string EmployeeNo { get; set; }
      public string Name { get; set; }
      public string Surname { get; set; }
      public string ContactInfo { get; set; }
      public int RoleId { get; set; }
  
      public virtual ICollection&lt;DeviceUsage&gt; DeviceUsages { get; set; }
      public virtual Role Role { get; set; }
  }
  </code></pre>
  
  <p>In this case Only Role is validated because it's foreign key from other table</p>