How to display a list using ViewBag

前端 未结 9 2047
孤街浪徒
孤街浪徒 2020-12-05 03:07

Hi i need to show a list of data using viewbag.but i am not able to do it.
Please Help me..
I tried this thing:

 ICollection list = ne         


        
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 03:34

    i had the same problem and i search and search .. but got no result.
    so i put my brain in over drive. and i came up with the below solution. try this in the View Page

    at the head of the page add this code

     @{
          var Lst = ViewBag.data as IEnumerable;
        }
    

    to display the particular attribute use the below code

    @Lst.FirstOrDefault().FirstName
    

    in your case use below code.

    @Lst.FirstOrDefault().FirstName   
    

    Hope this helps...

提交回复
热议问题