我希望用户能够使用下拉列表Sitecore的MVC标准渲染参数
我创建了从标准渲染参数继承为基础模板和标准值有$一个新的模板选择背景颜色名令牌
这里是模板颜色的定义:
ColorName --- DropLink ---/Sitecore的/内容/首页/全球/颜色
[SitecoreType(TemplateId = "{55DB8F6A-807D-48F8-A3D1-D81037938F13}", AutoMap = true)]
public interface IColor:IContentBase
{
string ColorName { get; set; }
}
我也创建模板的多个实例(红,蓝,绿)
然后我给你颜色模板的ViewRendering作为参数。
最后,CSHTML文件中,我尝试读取这个参数
@using Glass.Mapper.Sc
@model INews
<H3> Hot News: </H3>
@{
var rendering = RenderingContext.Current.Rendering;
string id = rendering.Parameters["ColorName"];
var context = new SitecoreContext();
var result=context.GetItem<IColor>(new Guid(id));
}
<div style="background-color: @NewsRepository.GetBackgroundColor(rendering);" class="panel-body">
<br/>
<span>@result.ColorName</span><br/>
@Model.Title
</div>
结果总是{55DB8F6A-807D-48F8-A3D1-D81037938F13},而我希望的 “绿色”。还试图使用SiteMap API的GlassMapper instaed但仍然得到Guid。
谢谢您的回答。 我已经定义了IColor类。但玻璃映射返回Guid –
你需要更新你的原始问题的细节,但它应该工作。确保您已发布所有模板和项目。 – jammykam