Skip to main content
Home  › ... Razor

Data Tutorials

Tutorial HomeData

Example from DNN Data

DNN also provides a lot of data about users, pages etc. In this example, we'll list all the pages (tabs) in DNN and mark the one we're on. Please note that the DNN API isn't very consistent - so sometimes things use ID, sometimes Id, so best really verify the exact names as spelled in the API.

@{
  // get the pages
  var pages = DotNetNuke.Entities.Tabs.TabController.GetPortalTabs(CmsContext.Site.Id, 0, true, false);
  var current = DotNetNuke.Entities.Tabs.TabController.CurrentPage;
}

<ul>
  @foreach (DotNetNuke.Entities.Tabs.TabInfo dnnPage in pages) {
    <li class='@(dnnPage.TabID == current.TabID ? "selected" : "")'>
      <a href="@dnnPage.FullUrl" target="_blank">
        @dnnPage.TabName (#@dnnPage.TabID)
      </a>
    </li>
  }
</ul>

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade;
@using System.Linq;
@using System.Collections.Generic;
<!-- unimportant stuff, hidden -->


<div @Sys.PageParts.InfoWrapper()>
  @Html.Partial("../shared/DefaultInfoSection.cshtml")
  <div @Sys.PageParts.InfoIntro()>
    <h2>Example from DNN Data</h2>
    <p>
      DNN also provides a lot of data about users, pages etc. In this example, we'll list all the pages (tabs) in DNN and mark the one we're on. 
      Please note that the DNN API isn't very consistent - so sometimes things use <code>ID</code>, sometimes <code>Id</code>, so best really verify the exact names as spelled in the API.
    </p>
  </div>
</div>


@{#if NETCOREAPP}
  @Html.Partial("../shared/MessageOqtaneDisabled.cshtml")
@{#else}

  @{
    // get the pages
    var pages = DotNetNuke.Entities.Tabs.TabController.GetPortalTabs(CmsContext.Site.Id, 0, true, false);
    var current = DotNetNuke.Entities.Tabs.TabController.CurrentPage;
  }

  <ul>
    @foreach (DotNetNuke.Entities.Tabs.TabInfo dnnPage in pages) {
      <li class='@(dnnPage.TabID == current.TabID ? "selected" : "")'>
        <a href="@dnnPage.FullUrl" target="_blank">
          @dnnPage.TabName (#@dnnPage.TabID)
        </a>
      </li>
    }
  </ul>


@{#endif}

@* Footer *@
@Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })