2
Vote

Incorrect Caching behaviour for the layout

description

I've found the one issue, but I don't know how to fix it correctly. Maybe you can help.

Imagine that you have 2 templates, and both use the same layout file. Layout doesn't have "@model" declaration while template 1 has "@model List<..>" and template 2 has "@model MyClass".

When you perform RazorEngine.Razor.Parse(template1, model1, ...);, Razor caches layout and remembers the type of the current model.

When you perform RazorEngine.Razor.Parse(template2, model2, ...);, Razor loads layout from the cache but throws an exception because it tries to cast model2 to the type of model1.

On my mind, Razor shouldn't remember the type of the model for the layout caching.

comments

antscode wrote Oct 31, 2014 at 1:43 AM

I'm having the same problem :( Kind of renders the layout functionality useless...