shyama
shyama

Reputation: 331

System.Collections.Generic.List`1[System.String] issue in mvc4

I am working with mvc4 and C#

i have a model

 public class Prod {
    private List<string> _photos;      
    public int Id { get; private set; }
    public string Name { get; set; }       

    public IEnumerable<string> Photos {
        get {
            if (_photos == null) {
                getPhotos();
            }
            return _photos;
        }
        private set{
            _photos = value.ToList();
        }
    }

and take this in a list at controller

  List<Prod> products = new Products().ToList();            
  return View(products);

in Photos contain a string i try to show that string in View page,

@model List<...Products.Prod>
 @foreach (var pro in Model)
 {
     @pro.Photos;
 }

i got the value as System.Collections.Generic.List`1[System.String]. How can i get corresponding string.

Upvotes: 1

Views: 7722

Answers (1)

user3559349
user3559349

Reputation:

Property Photos is a collection so

@foreach (var pro in Model)
{
  @pro.Name;
  foreach (string item in pro.Photos)
  {
    @item;
  }
}

Upvotes: 4

Related Questions