asp.net-mvcsitecoresitecore8sitecore-mvcglass-mapper

Sitecore MVC Standard Rendering Parameters


I want to user be able to select background-color using a drop-down list

I've created a new template which inherits from Standard Rendering Parameters as base template and standard value has $name token

Here is template Color definition:
ColorName---DropLink---/sitecore/content/Home/Global/Colors

    [SitecoreType(TemplateId = "{55DB8F6A-807D-48F8-A3D1-D81037938F13}", AutoMap = true)]
public interface IColor:IContentBase
{
    string ColorName { get; set; }
}

I also have created multiple instances of template (Red,Blue,Green)

enter image description here

Then I assign Color template to a ViewRendering as parameter.

enter image description here

Finally, in cshtml file, I try to read this parameter

@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>

The result is always {55DB8F6A-807D-48F8-A3D1-D81037938F13} whereas I expect "Green". Also tried to use Sitecore APIs instaed of GlassMapper but still I get Guid .


Solution

  • Try to use the following

    @result.ColorName.Value.Tostring();