【发布时间】:2020-06-22 12:54:55
【问题描述】:
Q) 我如何访问我的网站内容,例如我的 WebAPI 类中的书籍收藏?
在 Umbraco 8 网站项目中,我在我的 razor 视图中使用以下内容来获取内容,效果很好,然后我可以遍历集合并构建我的页面,一切都很好。
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using ContentModels = Umbraco.Web.PublishedModels;
@using System.Text.RegularExpressions;
@{
var books = Model.Root().DescendantsOfType("Book")
.Cast<Book>().Where(x => x.ShowInWebsite);
}
//...
但是,这不能在我的 WebAPI 类中编译 - 我不知道如何修复所需的引用。
我遇到的错误:
The name 'Model' does not exist in the current context
我尝试过的其他方法:
var books = Umbraco.ContentAtRoot().DescendantsOrSelf().OfTypes("Book");
// 报错:
IEnumerable<IPublishedContent>' does not contain a definition for 'DescendantsOrSelf' and the best extension method overload 'PublishedContentExtensions.DescendantsOrSelf(IPublishedContent, string)' requires a receiver of type 'IPublishedContent
【问题讨论】: