-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added flashes with a couple of examples
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Microsoft.AspNetCore.Mvc | ||
{ | ||
public static class FlashMessages | ||
{ | ||
public static string Info = "InfoMessage"; | ||
public static string Success = "SuccessMessage"; | ||
public static string Error = "ErrorMessage"; | ||
public static string Warning = "WarningMessage"; | ||
} | ||
|
||
//TODO: allow mulitple flashes of same type??? | ||
public static class ControllerExtensions | ||
{ | ||
static void FlashMessage(this Controller controller, string type, string message) | ||
{ | ||
controller.TempData[type] = message; | ||
} | ||
public static void FlashInfo(this Controller controller, string message) | ||
{ | ||
FlashMessage(controller, FlashMessages.Info, message); | ||
} | ||
|
||
public static void FlashSuccess(this Controller controller, string message) | ||
{ | ||
FlashMessage(controller, FlashMessages.Success, message); | ||
} | ||
|
||
public static void FlashError(this Controller controller, string message) | ||
{ | ||
FlashMessage(controller, FlashMessages.Error, message); | ||
} | ||
|
||
public static void FlashWarning(this Controller controller, string message) | ||
{ | ||
FlashMessage(controller, FlashMessages.Warning, message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@using Microsoft.AspNetCore.Mvc.RazorPages | ||
|
||
@if (TempData.ContainsKey(FlashMessages.Error)) | ||
{ | ||
<div class="alert alert-danger">@TempData[FlashMessages.Error]</div> | ||
} | ||
|
||
@if (TempData.ContainsKey(FlashMessages.Info)) | ||
{ | ||
<div class="alert alert-info">@TempData[FlashMessages.Info]</div> | ||
} | ||
|
||
@if (TempData.ContainsKey(FlashMessages.Warning)) | ||
{ | ||
<div class="alert alert-warning">@TempData[FlashMessages.Warning]</div> | ||
} | ||
|
||
@if (TempData.ContainsKey(FlashMessages.Success)) | ||
{ | ||
<div class="alert alert-success" role="alert">@TempData[FlashMessages.Success]</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters