Engage on Facebook Engage on Twitter Engage on LinkedIn Engage on GitHub components notes mobile card heart 2 infinite mirror 2 pricing support

Get Module by Module ID in DotNetNuke

By Brian Dukes

When building DotNetNuke modules, a number of times I've run up against the issue of trying to instantiate a ModuleInfo instance with only a module ID.  However, the GetModule signature on ModuleController takes both a module ID and a tab ID.  In this latest instance where I've come against this issue, I was actually trying to get a tab ID based on the module ID, so I obviously didn't already had one to provide. 

As I started to move down the road of writing my own query to get this simple thing done, I found that the GetModule method and underlying query will take a "null" value for the tab ID!  Unbeknownst to me, the solution was right in front of me, right where I expected it to be the whole time, I just couldn't see it.

So, if you need a ModuleInfo instance and you only have a module ID, call GetModule(moduleId, Null.NullInteger) and you're good to go!

(I've put in a request with the people in charge to add an overload to GetModule so that this is more obvious going forward)

Planning a DNN upgrade? Download our guide