title: Display viewdata in asp.net 4.0 mvc
body: <p>What ia m trying to do is display a success message after the query has been executed succesfully on database. Everything is working fine except my viewdata which does not display anything on view page. Not sure why. Below is my code please help me guys.</p>
  
  <pre><code>public class SearchItem
  {
      [Required(ErrorMessage = "Required Field")]
      public string searchItem { get; set; }
  }
  
  
      public ActionResult Index()
      {
          try
          {
              ViewData["SuccessMessage"] = "";
              return View();
          }
          catch (Exception ex)
          {
              return View("EmptySearch");
          }
      }
  
      [HttpPost]
      public ActionResult Index(string searchItem)
      {
          try
          {
               ............
              //database query with searchItem
              ...............
  
              string suceesstring = "A WAREHOUSE HOLD has been added.";
              ViewData["SuccessMessage"] = suceesstring;
              return View();
          }
          catch (Exception ex)
          {
              return View("EmptySearch");
          }
      }
  </code></pre>
  
  <p>And here is my view page:</p>
  
  <pre><code>@model KeleIntegratedTools.Models.SearchItem
  
  @{
      ViewBag.Title = "Great Plains hold Insert Utility";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt; h2&gt;Great Plains hold Insert Utility&lt;/h2&gt;
  &lt; p class ="PenColor" &gt;
  Please enter order number to place on warehouse hold.
  </code></pre>
  
  <p></p></p>
  
  <pre><code>@using (Html.BeginForm("Index", "GreatPlains"))
  
  {
  
  &lt; div&gt;
      &lt; fieldset&gt;
          &lt; legend&gt;Order Information&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Order Number")
  
              @Html.TextBox("searchItem")
              @Html.ValidationMessageFor(m =&gt; m.searchItem)
              @Html.Label(ViewData["SuccessMessage"].ToString())
          &lt;/div&gt;
          &lt;p&gt;
              &lt;input type="submit" value="Search" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  &lt;/div&gt;
  }
  </code></pre>