title: MVC issue for accessing the data from database:The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32'
body: <p>I am working on MVC where I am trying to access data from the database. I am new to MVC. I am getting the following error:</p>
  <blockquote>
  <p>The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'MVCDemo1.Controllers.EmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.</p>
  <p>Parameter name: parameters</p>
  </blockquote>
  <p>Code:</p>
  <pre><code>Database.SetInitializer&lt;MVCDemo1.Models.EmployeeContext&gt;(null);
  </code></pre>
  <p>I have added the above line in <code>global.asax.cs</code> file and I am getting the error there.</p>
  <p>The below is my Model:Employee.cs</p>
  <pre><code>namespace MVCDemo1.Models
  {
      [Table(&quot;tblEmployee&quot;)]
      public class Employee
      {
          [Key]
          public int EmployeeId { get; set; }
          public string Name { get; set; }
          public string Gender { get; set; }
          public string City { get; set; }
      }
  }
  </code></pre>
  <p>The below is my code for the Controller:EmployeeController</p>
  <pre><code>public ActionResult Details(int id)
          {                    
                  EmployeeContext employeeContext = new EmployeeContext();
                  Employee employee = employeeContext.Employees.Single(x =&gt;           x.EmployeeId == id);
  
                  return View(employee);
                              
      }
  </code></pre>
  <p>The below code is for View:details.cshtml</p>
  <pre><code>@model MVCDemo1.Models.Employee
  
      @{
          ViewBag.Title = &quot;Employee Details&quot;;
      }
      
      &lt;h2&gt;Employee Details&lt;/h2&gt;
      
      &lt;table style=&quot;font-family:Arial&quot;&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Employee ID:
              &lt;/td&gt;
              &lt;td&gt;
                  @Model.EmployeeId
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Name:
              &lt;/td&gt;
              &lt;td&gt;
                  @Model.Name
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Gender:
              &lt;/td&gt;
              &lt;td&gt;
                  @Model.Gender
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  City:
              &lt;/td&gt;
              &lt;td&gt;
                  @Model.City
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>
  <p>My Route configPath is:</p>
  <pre><code>defaults: new { controller = &quot;Employee&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }
  </code></pre>
  <p>Can anyone enlighten me with this error?</p>
  <p>I tried by removing <code>id = UrlParameter.Optional</code> from routeconfig but not worked for me.</p>