Sitecore/GlassMapper获取页面

Rad*_*adu 1 c# sitecore glass-mapper sitecore8 sitecore8.1

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

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

Vla*_*giu 5

例如,如果您有一个主页和字段标题,则将当前页面转换为HomePage模型

  var context = new SitecoreContext();
  Model = context.GetCurrentItem<HomePage>(); 
Run Code Online (Sandbox Code Playgroud)

其中模型的定义如下:public HomePage Model {get; 组; }

在您看来,您将拥有:

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

 <title>@Model.Title</title>
Run Code Online (Sandbox Code Playgroud)

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

如果您想在页面编辑器中进行编辑,可以使用:

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