title: My modelstate is always invalid even if there are no errors on the data entered by the user
body: <p>Hi I have a method in my controller and has the following code</p>
  
  <pre><code>if (ModelState.IsValid)
  
  {
  
      IDataOperations ops = DataSession.GetDataOperations(null);
      List&lt;Department&gt; dept = new List&lt;Department&gt;();
      ops.Load(dept);
      ops.Commit();
      int deptId = dept[dept.Count - 1].Id + 1;
      Department department = new Department()
      {
        Id = deptId,
        CompanyId = deptModel.CompanyId,
        Active = deptModel.Active,
        Name = deptModel.Name
      };
  
      ops.Create(department);
      ops.Commit();
      return RedirectToAction("CompanyDepartment", "Task");
  }
  
  else
  
  {
    //some code
  </code></pre>
  
  <p>Every time the page runs it always goes to the else part, meaning model-state is invalid.
  How do I check where the error in the page is, what code can I add to show where the error in the page is.</p>
  
  <p>Thank you</p>