c# - Sitecore/GlassMapper 获取页面

标签 c# sitecore sitecore8 glass-mapper sitecore8.1

我正在使用 Sitecore 8.1 和 GlassMapper 来映射 C# 中的字段。 我正在为开发的组件使用数据源。

我需要能够从我们当前所在的页面中获取一个字段。您知道如何获取在 Sitecore 中定义的页面对象吗?

最佳答案

例如,如果您有主页和字段标题 您将当前页面转换到主页模型

  var context = new SitecoreContext();
  Model = context.GetCurrentItem<HomePage>(); 

模型的定义如下: 公共(public)主页模型 { get;放;

在您看来,您将拥有:

@inherits System.Web.Mvc.WebViewPage<Namespace.HomePage>

 <title>@Model.Title</title>

另请检查此链接:http://glass.lu/Mapper/Sc/Tutorials/Tutorial12

如果你想让它在页面编辑器中可编辑,你可以使用:

http://glass.lu/Mapper/Sc/Tutorials/Tutorial14

关于c# - Sitecore/GlassMapper 获取页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36933903/

相关文章:

c# - "Access to disposed closure"using语句警告

sitecore - 有没有办法强制 Sitecore 将 MongoDB 数据与其 SQL 数据库同步?

asp.net-mvc - 使用 glassmapper 在 Sitecore MVC 中重用多个模型的 View

c# - 使用 Google Analytics 跟踪文本框条目

c# - 针对 IEnumerable 字段查询 lucene 索引

c# - 在 CSharpScript 的脚本类中访问全局变量

c# - 我的 lambda 表达式有什么问题

c# - 方法组不可分配给 Icomparer<DateTime>

c# - 访问同一页面上另一个 Webcontrol 中的标签

solr - 使用 Solr 和 Tika 索引 PDF 内容