When I try to assign a value to the ViewBag I get the following error:
Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'
My code is as follows:
public ActionResult Success() { ViewBag["SuccessBody"] = TempData["successBody"]; return View(); }
PS: Why I do this you may ask? Because I am redirecting to the Success action and I needed something that persists across redirects. Then, I am assigning the value to ViewBag in order to pass the Value to a 'shared' view.
ViewBag is a dynamic wrapper for ViewData, so these two statements are the same:
ViewBag.SuccessBody = TempData["successBody"]; ViewData["SuccessBody"] = TempData["successBody"];
Have you tried
ViewBag.SuccessBody = TempData["successBody"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With