-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlashMessageHtmlHelper.cs
More file actions
47 lines (42 loc) · 1.34 KB
/
FlashMessageHtmlHelper.cs
File metadata and controls
47 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using FlashMessage.Enums;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace FlashMessage.TagHelpers
{
/// <summary>
/// A TagHelper for the Flash Message feature for easy use in Razor pages.
/// </summary>
[HtmlTargetElement("flash")]
public class FlashTagHelper : TagHelper
{
private readonly IFlash _flash;
[HtmlAttributeName("type")]
public string Type { get; set; } = "any";
public FlashTagHelper(IFlash flash)
{
_flash = flash;
//flash.LoadSession();
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
FlashMessageCategory category;
if (!Enum.TryParse(Type, true, out category))
category = FlashMessageCategory.Any;
output.TagName = "div";
output.TagMode = TagMode.StartTagAndEndTag;
string flashContent = _flash.ToString(category);
if (!string.IsNullOrEmpty(flashContent))
{
output.Content.SetHtmlContent(flashContent);
}
else
output.SuppressOutput();
}
}
}