GlassMapper 4.0.1.8和Sitecore 8(rev.150621):查看渲染模型错误

时间:2015-10-18 00:22:02

标签: sitecore sitecore8 glass-mapper sitecore-mvc

尝试使用流畅的配置映射时,我尝试渲染视图渲染而不在sitecore中指定模型,如下面的链接所示。

http://www.glass.lu/Blog/GlassV4

当我转到该页面时,我收到以下错误。

The model item passed into the dictionary is of type
'Sitecore.Mvc.Presentation.RenderingModel'
but this dictionary requires a model item of type 'TestModel'.
Description: An unhandled exception occurred.

Exception Details: System.InvalidOperationException: The model item
passed into the dictionary is of type
'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary
requires a model item of type 'TestModel'.

[InvalidOperationException: The model item passed into the dictionary
is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this
dictionary requires a model item of type 'TestModel'.]   
System.Web.Mvc.ViewDataDictionary1.SetModel(Object value) +381   
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
+692    System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary     viewData) +74    System.Web.Mvc.RazorView.RenderView(ViewContext
viewContext, TextWriter writer, Object instance) +137   
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper,
String partialViewName, Object model, ViewDataDictionary viewData)
+167    Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)   +223

我还没有在视图渲染中指定任何模型,下面是我的模型和流畅的配置类。

TestModel.cs从Treelist字段中获取项目:

public class TestModel
{
    public virtual IEnumerable<GlassGeneratedModel> MediaItems { get; set; } 
}

TestModelFluentConfig.cs

public class TestModelFluentConfig: SitecoreGlassMap<TestModel>
{
    public override void Configure()
    {
        Map(
            x => x.AutoMap(),
            x =>  x.Field(y =>  y.MediaItems ).FieldName("Treelist Field Name")
            );
    }
}

GlassMapperScCustom.cs

public static void AddMaps(IConfigFactory<IGlassMap> mapsConfigFactory)
    {
        // Add maps here

        mapsConfigFactory.Add(() => new TestModelFluentConfig());
    }

我缺少一些步骤吗?我使用此链接中提到的处理器作为Glass配置文件:

https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/App_Config/Include/Glass.Mapper.Sc.config

任何帮助都将不胜感激。

0 个答案:

没有答案