Skip to main content
Home  › ... Razor

Data Tutorials

Tutorial HomeData

Using an App.Query multiple times

The previous examples showed how to use an App.Query. Now we want to run the query twice, which requires a Reset().
Note that the parameter PortalId is preset to be [Portal:PortalId].



    @{
      // get the query and ask for the "Default" results as a dynamic List
      var query = App.Query["DnnFilesFromSql"];
      var currentFiles = AsList(query);
      query.Reset();
      query.Params("PortalId", "0");
      var rootFiles = AsList(query);
    }
    

files from the current Portal

  • image-1.jpg
  • image-2.jpg
  • ct basic content.png
  • ct image.png
  • ct layout element.png
  • ct links.png
  • ct location.png
  • ct person.png
  • ct video.png
  • RazorTutoApp1000x1000.png

    <ul>
      @foreach(var file in currentFiles) {
        <li>@file.FileName</li>
      }
    </ul>
    

Files from the root portal

  • 2sic120px.gif
  • WYSIWYG.css
  • PlaceHolder.txt
  • PlaceHolder.txt
  • Default.page.template
  • Chrysanthemum.jpg
  • DemoImage.jpg
  • DemoImageBox.jpg
  • DemoImageBox2.jpg
  • DemoImagex-y.jpg

<ul>
  @foreach(var file in rootFiles) {
    <li>@file.FileName</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.Razor12
<!-- unimportant stuff, hidden -->
@using ToSic.Razor.Blade;
@using System.Linq;
Using an App.Query multiple times The... <!-- unimportant stuff, hidden -->
<div class="row">
  <div class="col-lg-7">
    
    @{
      // get the query and ask for the "Default" results as a dynamic List
      var query = App.Query["DnnFilesFromSql"];
      var currentFiles = AsList(query);
      query.Reset();
      query.Params("PortalId", "0");
      var rootFiles = AsList(query);
    }
    
    

    <h2>files from the current Portal</h2>
    
    <ul>
      @foreach(var file in currentFiles) {
        <li>@file.FileName</li>
      }
    </ul>
    
    
  </div>
  <div class="col-lg-5">
    @fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-dnn-files.png", width, height, "float-left", label: "Query Tree") 
    @fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-configuration.png", width, height, "float-left", label: "Query Configuration with Params and Test-Values")
    @fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-select-statement.png", width, height, "float-left", label: "SQL Query using Params")
  </div>
</div>

<hr>
<h2>Files from the root portal</h2>

<ul>
  @foreach(var file in rootFiles) {
    <li>@file.FileName</li>
  }
</ul>



<!-- unimportant stuff, hidden -->