How to display a list using ViewBag

前端 未结 9 2043
孤街浪徒
孤街浪徒 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:16

    Use as variable to cast the Viewbag data to your desired class in view.

    @{
    
    IEnumerable personlist = ViewBag.data as
    IEnumerable;
    // You may need to write WebApplication.Models.Person where WebApplication.Models is
      the namespace name where the Person class is defined. It is required so that view 
      can know about the class Person. 
    }
    

    In view write this

    
        @(personlist.FirstOrDefault().Name)
    
    

提交回复
热议问题