我正在使用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);
照片中的包含一个字符串,我试图在View页面中显示该字符串,
@model List<...Products.Prod>
@foreach (var pro in Model)
{
@pro.Photos;
}
我得到的值是System.Collections.Generic.List`1 [System.String]。我怎样才能获得相应的字符串。
答案 0 :(得分:2)
属性Photos
是一个集合,所以
@foreach (var pro in Model)
{
@pro.Name;
foreach (string item in pro.Photos)
{
@item;
}
}