title: How to show error message in asp.net mvc3
body: <p>Please help me to show Error message in the view. My code is given below - </p>
  
  <p>This is my View Model:</p>
  
  <pre><code>public class DepartmentViewModel
  {
      //public Department Department { get; set; }
      public string DepartmentId { get; set; }
      [Required]
      public string DepartmentName { get; set; }
      public string ManagerMemberId { get; set; }
      public bool IsActive { get; set; }
      public List&lt;Member&gt; Managers { get; set; } 
  }
  </code></pre>
  
  <p>This is Controller:</p>
  
  <pre><code>public class DepartmentController : Controller
  {
      //
      // GET: /Department/
  
      public ActionResult Index()
      {
          var adminUserId = (string)Session["UserId"];
          var memberId = (string)Session["MemberId"];
  
          List&lt;Department&gt; departments = null;
  
          if (!string.IsNullOrEmpty(adminUserId))
          {
              departments = new DepartmentManager().GetDepartments(false);
          }
          else if (!string.IsNullOrEmpty(memberId))
          {
              var companyId = (int)Session["CompanyId"];
              departments = new DepartmentManager().GetDepartments(false, companyId);
          }
  
          //var managers = new MemberManager().GetMembersOfManagerCategory(true, );
  
          return View("DepartmentList", departments);
      }
  
  
      public ActionResult Delete(string departmentId)
      {
          try
          {
              new DepartmentManager().DeleteDepartment(departmentId);
          }
          catch (System.Exception exception)
          {
              ModelState.AddModelError("Error", "Unable to delete department. Try again,      and if the problem persists see your system administrator.");
              //return RedirectToAction("Index", "Department");
          }
  
          return RedirectToAction("Index", "Department");
      }
  }
  </code></pre>
  
  <p>This is View:</p>
  
  <pre><code>@model IEnumerable&lt;PDCA.Core.EntityClasses.Department&gt;
  @{
      ViewBag.Title = "Department List";
      Layout = "~/Views/Shared/_Layout.cshtml";
   }
  &lt;div class="container"&gt;
  @using (Html.BeginForm())
  {
      &lt;form class="form-horizontal"&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;List of Departments:&lt;/legend&gt;
          &lt;table border="1" cellspacing="1"&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Id
                  &lt;/th&gt;
                  &lt;th&gt;
                      Name
                  &lt;/th&gt;
                  &lt;th&gt;
                      Company
                  &lt;/th&gt;
                  &lt;th&gt;
                      Manager
                  &lt;/th&gt;
                  &lt;th&gt;
                      IsActive
                  &lt;/th&gt;
                  &lt;th&gt;
                  &lt;/th&gt;
              &lt;/tr&gt;
              @foreach (var item in Model)
              {
                  &lt;tr&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.DepartmentId)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.DepartmentName)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.Company.CompanyName)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.Manager.MemberName)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.IsActive)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.ActionLink("Edit", "Edit", new { item.DepartmentId }) |
                          @Html.ActionLink("Delete", "Delete", new { item.DepartmentId })
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/table&gt;
          &lt;p&gt;&lt;/p&gt;
          &lt;p&gt;
              @Html.ActionLink("Create New", "Create")
          &lt;/p&gt;
          &lt;p&gt;&lt;/p&gt;
          &lt;p&gt;
              @Html.ValidationMessage("Error");
          &lt;/p&gt;
      &lt;/fieldset&gt;
      &lt;/form&gt;
  }
  </code></pre>
  
  <p></p>
  
  <p>In the view I put  @Html.ValidationMessage("Error") but the error message is not shown there.</p>