【发布时间】:2015-12-17 00:20:25
【问题描述】:
我正在测试 Umbraco 并尝试在页面上设置博客列表。我有一个自定义的 BlogMode.cs,如下所示:
public class BlogPostModel : RenderModel
{
public BlogPostModel() : base(UmbracoContext.Current.PublishedContentRequest.PublishedContent)
{
}
public string MainBlogImage { get; set; }
public string ImageAltText { get; set; }
public string Introduction { get; set; }
public string Category { get; set; }
public IEnumerable<IPublishedContent> BlogPosts { get; set; }
}
这很好用,因为我的模型也不具备上述属性。现在我要做的是使用以下方法获取所有博客文章:
var posts = Model.Content.Children.ToList();
但这会创建一个IPublishedContent 类型的列表。所以现在我不能在我的博客模型中使用Model.Introduction 或Model.ImageAltText 或任何其他属性,因为它的类型是IPublishedContent
我如何获得这个集合并使其成为BlogModel 类型?
【问题讨论】:
-
你想达到什么目的?我猜您想在带有标题、简介和链接的页面上显示博客列表。
-
是的,Tej,类似的东西,试图通过使用
Model.Introduction之类的东西来获取自定义属性
标签: c# asp.net-mvc model umbraco