kentico - Kentico IEnumerable在我的控制器中为空
问题描述
我正在使用标准方法来获取页面的属性:
ClientLogosDatasource datasourceItem = ClientLogosDatasourceProvider.GetClientLogosDatasource(datasourceNodeGuid, "en-us", SiteContext.CurrentSiteName)
.Columns("ClientLogosDatasourceHeadingText", "ClientLogosDatasourceImages");
其中有一个“附件”表单组件
但是当我尝试枚举我的 MVC 应用程序中的属性时,枚举是空的。
单步执行代码,它基本上完全跳过了 foreach。我不确定为什么 Images 属性为空/空。
任何帮助,将不胜感激!
解决方案
这是基本的API 示例(不是特定于 MVC 的),但应该让您朝着正确的方向前进。
// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Gets a page
TreeNode page = tree.SelectNodes()
.Path("/Articles")
.OnCurrentSite()
.Culture("en-us")
.TopN(1)
.FirstOrDefault();
if (page != null)
{
// Iterates over all attachments of the page
foreach (DocumentAttachment attachment in page.AllAttachments)
{
// Perform any action with the attachment object (DocumentAttachment)
}
}
// To get only unsorted attachments, use the TreeNode.Attachments collection
// To get only page field attachments, use the TreeNode.GroupedAttachments collection
推荐阅读
- python - 子进程标准输出解码字符串不适用于希腊字母
- javers - 从不同实例保存相同的通用提交对象
- java - 我无法保存整数
- javascript - 使用单个正则表达式仅提取函数名称(字符串值)
- sql - 如果在 case 语句中为 null,则将日期时间转换为字符串“待定”
- mysql - Heroku 重启与 Nodejs 重启不同
- javascript - 在 php 中回显 javascript 函数 - 在控制台中回显,但不运行 javascript 函数
- reactjs - ReactJS 应用程序使用 Kubernetes Ingress 显示白屏
- python - 如何从python列表中删除外引号?
- android - 更改微调器的颜色