mvc4中的System.Collections.Generic.List`1[System.String]问题

本文关键字:System String 问题 List 中的 Collections Generic mvc4 | 更新日期: 2023-09-27 18:28:56

我正在使用mvc4和C#

我有一个型号

 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]。如何获得相应的字符串。

mvc4中的System.Collections.Generic.List`1[System.String]问题

属性Photos是一个集合,因此
@foreach (var pro in Model)
{
  @pro.Name;
  foreach (string item in pro.Photos)
  {
    @item;
  }
}
相关文章: