2014-11-03 36 views
0

問題我與mvc4工作和C#System.Collections.Generic.List`1 [System.String]在mvc4

我有一個模型

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(); 
     } 
    } 

,並藉此在控制器列表

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

包含字符串我嘗試以顯示查看頁面的字符串,

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

我得到了System.Collections.Generic.List`1 [System.String]的值。我怎樣才能得到相應的字符串。

回答

2

物業Photos是一個集合,以便

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

謝謝.............. – shyama 2014-11-03 11:39:29

相關問題