title: Unable to read View Bag value from controller to view
body: <p>I have created a view bag in controller's post back event which stores the image path.
  Then,i used this view bag value in image src attribute.But image is not displayed.</p>
  
  <p>Model:</p>
  
  <pre><code>public class FileManagement
       {
      public string FileName { get; set; }
      public string Path { get; set; }
        }
  </code></pre>
  
  <p>Code for uploading image</p>
  
  <pre><code>      [HttpPost]
        public ActionResult UploadPic(FileManagement fmanage, HttpPostedFileBase file)
        {
          string email = User.Identity.Name;
  
          if (file != null &amp;&amp; file.ContentLength &gt; 0)
          {
              var FileName = string.Format("{0}.{1}", Guid.NewGuid(), Path.GetFileName(file.FileName));
              var path = Path.Combine(Server.MapPath("~/Content/Uploads"), FileName);
              file.SaveAs(path);
  
           using (var session = DocumentStore.OpenSession("RavenMemberShip"))
              {
  
                  var query = from q in Session.Query&lt;Registration&gt;() where q.Email == email select q;
                  if (query.Count() &gt; 0)
                  {
                      foreach (var updated in query)
                      {
                          updated.FileName = FileName;
                          updated.Path = path;
                          session.SaveChanges();
  
                      }
                  }
              }
          }
          else ModelState.AddModelError("", "Remove the errors and try again");
          return View();
      }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>    [HttpGet]
      public ActionResult DisplayPic()
      {
          ViewBag.Imagepath = "C:\\Users\\Wasfa\\Documents\\Visual Studio 2012\\Projects\\MvcMembership\\MvcMembership\\App_Data\\Uploads\\annonymous.jpg";
  
          return View();
      }
  
      [HttpPost]
      public ActionResult DisplayPic(FileManagement fm)
      {
  
  
          using (var session = DocumentStore.OpenSession("RavenMemberShip"))
          {
              string ipath;
              //  string UserName = User.Identity.Name;
              string UserName = "wasfa_anjum@yahoo.com";
              var getPath = from p in Session.Query&lt;Registration&gt;()
                            where p.Email == UserName
                            select p;
              if (getPath.Count() &gt; 0)
              {
                  foreach (var imgpath in getPath)
                  {
  
                      ipath = imgpath.Path;
                      ViewBag.Imagepath = ipath;
                  }
  
             }
  
          }
          return View();
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>    @using (Html.BeginForm())
  
     {
      &lt;div&gt;
      &lt;img src="@Url.Content(ViewBag.Imagepath)" width="200" height="200" /&gt;
      &lt;/div&gt;
      &lt;input type="submit" value="Display" /&gt;
     }
  </code></pre>