【发布时间】:2016-02-13 18:13:04
【问题描述】:
我想在局部视图中获取模型类型的名称和模型列表的标题,但 @genre.Lists.Title 不起作用 这是我的流派模型
public class Genre
{
public int GenreId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<List> Lists { get; set; }
}
这是我的列表模型
[Bind(Exclude = "ListId")]
public class List
{
[ScaffoldColumn(false)]
public int ListId { get; set; }
[DisplayName("Genre")]
public int GenreId { get; set; }
[DisplayName("Maker")]
public int MakerId { get; set; }
[Required(ErrorMessage = "An List Title is required")]
[StringLength(160)]
public string Title { get; set; }
[Required(ErrorMessage = "Price is required")]
[Range(0.01, 100.00,ErrorMessage = "Price must be between 0.01 and 100.00")]
public decimal Price { get; set; }
[DisplayName("List URL")]
[StringLength(1024)]
public string ListUrl { get; set; }
public Genre Genre { get; set; }
public Maker Maker { get; set; }
public virtual List<OrderDetail> OrderDetails { get; set; }
}
这是我的 actionResult
public ActionResult Navbar()
{
var genres = storeDB.Genres.Include("Lists").ToList();
return PartialView("Navbar",genres);
}
这是我的部分视图
@model IEnumerable<Store.Models.Genre>
@foreach (var genre in Model)
{
@genre.Name
@genre.Lists.Title
}
【问题讨论】:
标签: asp.net-mvc entity-framework