Ali Khakpouri Ali Khakpouri - 3 months ago 24
C# Question

DotNenuke Razor Host RenderPage pass in dynamic variablwe

I'm working with DNN 8.4.2 -
My partial looks like this this:

if(ViewBag.loadItem != null && ViewBag.loadItem)
//load my stuff

While my rendering looks like this:

@RenderPage("Shared/MyScript.cshtml",new{ loadItem = true })

But, when the page loads, i'm getting the following exception:
The name 'ViewBag' does not exist in the current context.

Is there anyway I can pass in a dynamic variable to a partial rendering in DNN's razor host?


Found the answer! There is no ViewBagin DNN's Razor Host module since it only works with a Model. You can use PageData instead.

var loadItem = PageData["loadItem"];
    if (loadItem != null && loadItem)
        //do stuff here