Requirements
Resources
Basic List Details using Code - with separate Details-File
Very often you have a list of items, and then a details-page showing just one item. In this example, we'll just use code to do this (so no visual query) - just so you understand the principle. This example splits the list/details templates into 3 files, which is easier to manage. File 1 choses what should happen, file 2 contains the list, and file 3 the details.
Since we'll look for the desired item in code, we'll use LINQ. To learn more about that, check out the LINQ Tutorials.
Output
List of Persons
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 List Details using Code - with separate Details-File</h2> <p> Very often you have a list of items, and then a details-page showing just one item. In this example, we'll just use code to do this (so no visual query) - just so you understand the principle. This example splits the list/details templates into 3 files, which is easier to manage. File 1 choses what should happen, file 2 contains the list, and file 3 the details. </p> <p> Since we'll look for the desired item in code, we'll use LINQ. To learn more about that, check out the @Sys.TutLink("LINQ Tutorials", "linq"). </p> </div> </div> @{ // check if we have a url-parameter called "id" with a value - defaults to 0 if not found int id = Kit.Convert.ToInt(CmsContext.Page.Parameters["id"]); } @if (id == 0) { @Html.Partial("611-list.cshtml") } else { @Html.Partial("611-details.cshtml", new { Id = id }) } @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })