We are currently converting a large application from WebForms to MVC. Our application has an idea of, what we call, dynamic resources in that we have items in Sitecore that specify resources (CSS/JS) and those can be attached to a page so they can be changed on the fly if need be. With this, we have both a sublayout (ascx) and a rendering (cshtml) that does the work to get these resources on the page.
In the dynamic resource (DR) template, we have 4 fields:
- External CSS - Multi-Line Field
- Internal CSS - Tree Ex
- External JS - Multi-Line Field
- Internal JS - Tree Ex
We want our code to represent this template like so:
string[] ExternalCss{get;set;}
IDynamicResourceItem[] InternalCss{get;set;}
string[] ExternalJs{get;set;}
IDynamicResourceItem[] InternalJs{get;set;}
As you are aware, the string[]
doesn't work because the Glass Mapper code doesn't inherently convert a Multi-Line Field to a string array; it puts the entire field value into the array as a single object.
I went and created an AbstractSitecoreFieldMapper
and registered it and it works great as the model for the MVC rendering. However, the ascx doesn't work. We pull the template information via the sublayout's Parameters, which I thought was the underlying issue. But even in my testing, if I pulled the DR item and used item.GlassCast
instead of GetRenderingParameters
, it still didn't work. I believe the pipeline for the MVC model mapping uses the AbstractSitecoreFieldMapper
while the other methods do not.
How do I go about mapping this correctly via GetRenderingParameters
?