0

I am trying to render a view rendering without specifying the model in sitecore while trying to use fluent configuration mapping as shown in the link below.

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

When I go to the page, I get the below error.

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

I haven't specified any model in the view rendering and below is my model and fluent config class.

TestModel.cs to grab items from Treelist field:

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());
    }

Is there some step I am missing? I am using the processors mentioned in this link for the Glass config file:

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

Any help would be appreciated.

Chitrang
  • 1
  • 4
  • does your view have @model TestModel on top ? – nsgocev Oct 18 '15 at 11:38
  • @nsgocev, yes it does. I tried specifying the model in the view rendering in sitecore which got rid of the error but the field does not get resolved and I do not get any results back from the treelist. The list returns empty. – Chitrang Oct 18 '15 at 14:25
  • are you sure your fieldName matches the actual name of the treelist? Also what happens if you change the type of the list to Guid ? Do you get the Ids ? – nsgocev Oct 18 '15 at 18:43
  • Hi @nsgocev, yes, I have specified the field name on top such as below. `public class TestModel { [SitecoreField("Treelist Field")] public virtual IEnumerable TreelistItems { get; set; } }` – Chitrang Oct 18 '15 at 19:11
  • 1
    Hi @ngsocev, the error has been fixed. The issue was with the config file which had a typo :-| due to which the Glass model pipelines were not being resolved. Thank you for your help. :) – Chitrang Oct 18 '15 at 19:37

0 Answers0