Thoughts from the Wet Coast

The musings of an ASP.NET Developer from Canada's We(s)t Coast

Module Development in DNN 8: 7 - Using the Client Resource Manager in MVC modules

Category: DotNetNuke
Last Modified: May 2 2017
Nov 16 2015

Peter Donker raised the question in the DNN Connect Facebook Group – “How can you access the Client Resource Manager in an MVC View?”.  I gave him the answer as a reply but I thought it would be good to provide a more accessible source for the information.

In a classic WebForm based module it is easy to register a javascript or css file by using one of the “pseudo” user controls “DNNJsInclude” or “DnnCssInclude” in the ascx file.  Alternatively, in the code-behind file you can use one of the Register methods of the ClientResourceManager class.  In order to use the ClientResourceManager class you need to reference the DotNetNuke.Web.Client assembly and pass in the user control’s Page property.  In an MVC View, you can add references (using statements) easy enopugh.  But how do you pass the Page property.

Thankfully, I came across the issue while developing the QuickSettings View for the DCC Viewer module, and so I added the Page property to the DNNHelper class.

So the answer to Peter’s question is you can just do it similarly to how you would do it in a WebForm code-behind file.

e.g.

@using DotNetNuke.Web.Client.ClientResourceManagement @{     ClientResourceManager.RegisterScript(Dnn.DnnPage, "~/DesktopModules/MVC/Dnn/DynamicContentViewer/ClientScripts/dcc.quickSettings.js");     ClientResourceManager.RegisterScript(Dnn.DnnPage, "~/Resources/Shared/scripts/dnn.utility.js"); }

Note the Dnn.DnnPage is used to pass the current WebForm page to the Client Resource Manager.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Categories

Tags