title: Any reason why my ViewBag is not working?
body: <p>I have following <code>ActionResult</code> in a <code>controller</code> and you can see that I set a message in the <code>ViewBag</code> if it's successful. Then on the <code>View</code> it should output that message if it's not empty. However, I can't get the message to display and I'm not seeing what the problem is. </p>
  
  <pre><code>[HttpPost]
          public ActionResult Create(FormCollection collection)
          {
              try
              {
                  context.Roles.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole()
                  {
                      Name = collection["RoleName"]
                  });
                  context.SaveChanges();
  
                  ViewBag.ResultMessage = "Role created successfully.";
                  return RedirectToAction("Index");
              }
              catch (Exception)
              {
                  return View();
              }            
          }
  </code></pre>
  
  <p>This is my Index.cshtml</p>
  
  <pre><code>@model IEnumerable&lt;Microsoft.AspNet.Identity.EntityFramework.IdentityRole&gt;
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Roles Listing &lt;/h2&gt;
  
  @ViewBag.ResultMessage
  
  @Html.ActionLink("Create New Role", "Create") | @Html.ActionLink("Manage User Role", "ManageUserRoles")
  
  &lt;div&gt;
      &lt;table class="table table-bordered table-condensed table-striped table-hover "&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;Role&lt;/th&gt;
                  &lt;th&gt;Action&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              @foreach (var role in Model)
              {
                  &lt;tr&gt;
                      &lt;td&gt;&lt;strong&gt;@role.Name&lt;/strong&gt;&lt;/td&gt;
                      &lt;td&gt;
                          &lt;span onclick="return confirm('Are you sure you want to delete @role.Name?')"&gt;&lt;a href="/Roles/Delete?RoleName=@role.Name" class="delLink" style="color:red;"&gt;Delete&lt;/a&gt;&lt;/span&gt; |
                          @Html.ActionLink("Edit", "Edit", new { roleName = @role.Name })
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>