Access a Viewbag like an Array?

后端 未结 5 1375
余生分开走
余生分开走 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:16

    Thanks for the posts but shortly after writing this I came up with this solution using a model & list as below this could also be done using viewbag instead of model.

    List list = new List();
                foreach (Models.AppModeInfo blah in Model.theAppModes)
                {
                    list.Add(blah.Name);
                }
    
                var AppModeText = "";
                switch (item.AppModeId)
                {
                    case 1:
                        AppModeText = list[0];
                        break;
                    case 2:
                        AppModeText = list[1];
                        break;
                    case 3:
                        AppModeText = list[2];
                        break;
                    case 4:
                        AppModeText = list[3];
                        break;
                    case 5:
                        AppModeText = list[4];
                        break;
                }
    

提交回复
热议问题