Access a Viewbag like an Array?

后端 未结 5 1390
余生分开走
余生分开走 2021-01-13 14:44

Imagine a view bag called

 ViewBag.Modes

this contains the following:

Simple
Advanced
Manual
Complete

Ho

5条回答
  •  天命终不由人
    2021-01-13 15:34

    ViewBag is a dynamic property, which complicates things a bit.

    For the behavior you're looking for, you might want to use ViewData instead. ViewData is a dictionary, which means you can access the values of each index using Linq:

    this.ViewData.Keys.ElementAt(0);
    

提交回复
热议问题