Making a page Event aware - PuzzleServer/mainpuzzleserver GitHub Wiki
Most of our pages need some kind of Event awareness in order to be workable, if for nothing else than to get the upper menu working properly. Thankfully the procedure for adding Event awareness is easy.
1. Modify the @page
attribute in your .cshtml file
The @page
attribute needs to have the route template modified to include the eventId
first. See any page in the Puzzles section for examples - for example:
- Puzzles/Index.cshtml has
@page "/{eventId}/Puzzles"
- Puzzles/Details.cshtml has
@page "/{eventId}/Puzzles/Details"
2. Derive your model class from EventSpecificPageModel
in your .cshtml.cs file
You just need to add a using ServerCore.ModelBases
to the file and change PageModel
to EventSpecificPageModel
.
This adds an Event
property that is bound to the eventId
parameter on the route template you specified in part 1. You can reference this property for any purpose you wish.
3. When linking to your page from any non-Event-aware page, add an asp-route-eventId
attribute
This is only needed when entering the Event-aware zone; when linking from one Event-aware page to another, the existing property is transferred. Accordingly, this is really only necessary when linking to the event from, say, Events/Index.cshtml. You need to specify the ID of the event. For example, since each Event on the Index page is generated by a variable called item
, you can say:
<a asp-page="/Puzzles/Index" asp-route-eventId="@item.ID">Puzzles</a>