【问题标题】:System.Collections.Generic.List`1[System.String] issue in mvc4mvc4 中的 System.Collections.Generic.List`1[System.String] 问题
【发布时间】:2014-11-03 19:39:51
【问题描述】:

我正在使用 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]。如何获取对应的字符串。

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    属性Photos 是一个集合,所以

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

    【讨论】:

      猜你喜欢
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      相关资源
      最近更新 更多