I've faced with the next problem:
I'm trying run .NET MVC site to use ViewBag for passing some data to my View. Here is the method where I setting the VeiwBag.
[HttpGet] [AllowAnonymous] public ActionResult Start() { ViewBag.BanReason = null; int userId; //Request with UserId, display ban reason if necessary if (Request.Params["UserId"] != null && int.TryParse(Request.Params["UserId"], out userId)) { ViewBag.BanReason = CheckIfUserBanned(userId); } ViewBag.Users = MvcApplication.Users; return View(); }
When I assign value to the ViewBag (for example ViewBag.BanReason = null;) I've got the RuntimeBinderException with the message
'System.Dynamic.DynamicObject' does not contain a definition for 'BanReason'.
I'm using Visual Studio 2012 with .NET 4.5 and local IIS server with ApplicationPool with .NET 4.0. On the other computer with the same configuration all works nicely and no exceptions is thrown.
Please don't advice to use other techniques like ViewData[""] and Creating a separate model, I don't want to change code that works nicely on the other machine.
I think this is miss-configuration issue. Any guesses will be appreciated. Thanks
your code is fine, ViewBag is having a Dynamic Properties, and in Runtime all the properties are being assigned.
This Exception is a common CLR Exception.. Try doing the Following steps it will work I hope. Open Visual Studio
if still problems occures
hope it helps, its working for me
Click Here for Detailed Images
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