find and solve || findandsolve.com
Please wait.....

Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'

Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'

An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code.Additional information: Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'.When I am trying to assign a value to the ViewBag in my actionname and afte that  I get the as the given ablove.

My code is as follows:

        [AllowAnonymous]
        public ActionResult Login(string returnUrl)
        {
            ViewBag["ComapanyName"] = "";
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }


Answers

Option 1.

Change the ViewBag keyword to ViewData and this should work because ViewBag is just a wrapper for ViewData.

ViewData, you access the items by indexing the appropriate key from the key value dictionary like this.

ViewBag and ViewData seem kind of interchangable, but there are different between how you access the data inside of them. Your issue pops up when you try to index into a ViewBag, which doesn't work.

Change ViewBag to ViewData like as:


ViewData["ComapanyName"]

Option 2.

ViewBag.Success= TempData["Success"];


Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

Comments



Report Response