Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit ff1001d

Browse files
committed
Update module 4 docs
1 parent 7710128 commit ff1001d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

docs/4. Add auth features.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ In this module we're going to add the capability for users to register and sign-
456456
1. Add the following edit form to `EditSession.cshtml`:
457457

458458
```html
459+
<h3>Edit Session</h3>
460+
459461
<form method="post" class="form-horizontal">
460462
<div asp-validation-summary="All" class="text-danger"></div>
461463
<input asp-for="Session.ID" type="hidden" />
@@ -496,7 +498,10 @@ In this module we're going to add the capability for users to register and sign-
496498
</div>
497499
</div>
498500
</form>
499-
<partial name="_ValidationScriptsPartial" />
501+
502+
@section Scripts {
503+
<partial name="_ValidationScriptsPartial" />
504+
}
500505
```
501506
1. Add code to handle the `Save` and `Delete` button actions in `EditSession.cshtml.cs`:
502507

@@ -590,6 +595,27 @@ on form posts:
590595
}
591596
```
592597

598+
> TempData-backed properties also flow across pages, so we can update the Index page to show the message value too, e.g. when the session is deleted
599+
600+
1. Copy the message display markup from the top of the `EditSession.cshtml` file to the top of the `Index.cshtml` file:
601+
``` html
602+
@if (Model.ShowMessage)
603+
{
604+
<div class="alert alert-success alert-dismissible" role="alert">
605+
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
606+
@Model.Message
607+
</div>
608+
}
609+
```
610+
1. Copy the properties from the `EditSession.cshtml.cs` Page Model class file to the `Index.cshtml.cs` Page Model too:
611+
``` csharp
612+
[TempData]
613+
public string Message { get; set; }
614+
615+
public bool ShowMessage => !string.IsNullOrEmpty(Message);
616+
```
617+
1. Rebuild and run the app then delete a session and observe it redirect to the home page and display the success message
618+
593619
## Create a Tag Helper for setting authorization requirements for UI elements
594620
We're currently using `if` blocks to determine whether to show parts of the UI based the user's auth policies. We can clean up this code by creating a custom [Tag Helper](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro).
595621

0 commit comments

Comments
 (0)