Question

I'm currently using razor to render some views in DotNetNuke and everything is working fine except for one thing I'm missing. I'm trying to get access to some module level methods such as EditUrl etc. but can't seem to figure out how to go about it.

This is what I have for my view, although it errors on EditUrl. I'm using RazorEngine.Render to render the view. There are some helpers that are including for basic DNN info but I can't seem to find anything like NavigateUrl or EditUrl.

Any ideas?

@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage<dynamic>

<div id="items-panel">
    <table>
        <thead>
            <tr>
                <th>Title</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Items)
            {
            <tr>
                <td>
                   <a href="@EditUrl("ItemId", item.ItemId, "ViewItem">@item.Title</a>
                </td>
            </tr>
            }
        </tbody>
    </table>
</div>
Was it helpful?

Solution

I found a way that seems to work for EditUrl by creating a helper method in the razor view shown below. It's a shame I have to do this because the ModuleInstanceContext is actually passed into the constructor of the RazorEngine but not exposed to the view. If anyone else finds a way around this I'd appreciate a comment.

@helper EditUrl(string keyName, string keyValue, string controlKey)
{
    @DotNetNuke.Common.Globals.NavigateURL(Dnn.Tab.TabID, controlKey, "mid="+Dnn.Module.ModuleID, keyName + "=" + keyValue)
}

Edit: The following method also worked well for me. I added a property to the model named ItemViewUrl with a placeholder token for the ItemId and then just did a replace in the view.

In the calling page:

dynamic model = new ExpandoObject();
model.Items = ItemRepository.List();
model.ViewItemUrl = EditUrl("ItemId", "[ITEMID]", "ViewItem");

and then in the Razor view:

<td><a href="@Model.ViewItemUrl.Replace("[ITEMID]",item.ItemId.ToString())">@item.Title</a></td>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top