#6 Query with Params - Run multiple times
Run an App Query multiple times on the same page
The previous examples showed how to use a Query
.
Now we want to run the query twice, which requires a Reset()
.
Note that the parameter SiteId
is preset to be [Site:Id]
.
Initial Code
The following code runs at the beginning and creates some variables/services used in the following samples.
@{
// Different query in DNN / Oqtane - eg. "SqlTop10FilesDnn"
var queryName = "SqlTop10Files" + CmsContext.Platform.Name;
// get the query and ask for the "Default" results as a dynamic List
// This case doesn't set parameters, so we're using the defaults (current site)
var query = Kit.Data.GetQuery(queryName);
var currentFiles = AsList(query);
// Get a fresh query, so we can use again with other parameters
query = Kit.Data.GetQuery(queryName, parameters: new {
SiteId = CmsContext.Platform.Name == "Dnn" ? 0 : 1
});
var rootFiles = AsList(query);
}
Files from the current Portal
Output
- 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.Name</li>
}
</ul>