Skip to main content
Home  › ... Razor

Data Tutorials

Tutorial HomeData
Requirements
Resources

Basic Example from App.Data

The easiest data to access comes from the current environment - like from the App or from DNN itself. The following example gets Persons data from the App.Data["Persons"] and just loops through them. This is similar to the example in the content tutorial, except that the data comes from the App.Data instead of the current instance Data.

Output

  • Douglas Adams
  • Terry Pratchett
  • Neil Gaiman
  • George Akerlof
  • Raphael Müller (not an author)
  • Ed Hardy
<ul>
  @foreach (var person in AsList(App.Data["Persons"])) {
    <li>
      @if (Text.Has(person.Mugshot)) {
        <img loading="lazy" src='@Link.Image(person.Mugshot, width: 50, height: 50, resizeMode: "crop")' width="50px" style="border-radius: 50%">
      }
      @person.FirstName  @person.LastName
    </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;
<!-- unimportant stuff, hidden -->


<div @Sys.PageParts.InfoWrapper()>
  @Html.Partial("../shared/DefaultInfoSection.cshtml")
  <div @Sys.PageParts.InfoIntro()>
    <h2>Basic Example from App.Data</h2>
    <p>The easiest data to access comes from the current environment - like from the App or from DNN itself. The following example gets <code>Persons</code> data from the <code>App.Data["Persons"]</code> and just loops through them. This is similar to the example in the @Sys.TutLink("content", "content") tutorial, except that the data comes from the <code>App.Data</code> instead of the current <em>instance</em> <code>Data</code>.</p>
  </div>
</div>

  <ul>
    @foreach (var person in AsList(App.Data["Persons"])) {
      <li>
        @if (Text.Has(person.Mugshot)) {
          <img loading="lazy" src='@Link.Image(person.Mugshot, width: 50, height: 50, resizeMode: "crop")' width="50px" style="border-radius: 50%">
        }
        @person.FirstName  @person.LastName
      </li>
    }
  </ul>



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