Access a Viewbag like an Array?
问题 Imagine a view bag called ViewBag.Modes this contains the following: Simple Advanced Manual Complete How can I access the viewbag by index like you would in an array? e.g Simple is at index 0 then it would look like this ViewBag.Modes[0] I tried the above but it doesn't work so...How can I replicate this with viewbag or is there a workaround I can use? 回答1: This does the trick for me: Controller: public ActionResult Index() { var stringArray = new string[3] { "Manual", "Semi", "Auto"};