【发布时间】:2021-05-06 01:32:26
【问题描述】:
我在自定义 2sxc 应用 (AppId = 10) 中有一个 Content-Type。内容类型名称是“SeasonSettings”,其中包含颜色、字体、图标和图像,用于每年修改几次网站的主题。没有视图或模块,客户端通过进入应用程序的管理、数据选项卡等来获取设置。
当尝试从 Home.ascx 中我的皮肤文件的 C# 代码访问它时,我有以下内容:
// the details you need to know
var appId = 7; // The AppId that of the target Content Type
string ctName = "SeasonSettings"; // The name of the Content Type
int entityId = 2345; // The EntityId of the item with our settings
// get a handle to the App
var app7 = ToSic.Sxc.Dnn.Factory.App(appId);
现在我被困住了。由于我没有模块,因此我无法获得需要获取 DynamicCode 的 CmsBlock (BlockBuilder),因此我可以使用 AsList、AsEntity、AsDynamic 等。
所以我接下来的步骤是这样的:
// this fails because "AsList" is unknown
var setting = AsList(app7.Data[ctName])
.Where(e => e.EntityId == entityId)
.First()
;
<p>Color: @setting.BgColor</p>
无需在页面上放置模块/视图并使用 CmsBlock(tabId, moduleId) 等,还有其他方法可以从 app7 获取 DynamicCode 或任何调用/使用 AsList() 的方法吗?
【问题讨论】:
标签: dotnetnuke 2sxc