1

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.

1 Answer 1

4

Property Photos is a collection so

@foreach (var pro in Model)
{
  @pro.Name;
  foreach (string item in pro.Photos)
  {
    @item;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.