ModalHelper.cs 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.JSInterop;
  7. namespace EasyTemplate.Service
  8. {
  9. public class ModalHelper
  10. {
  11. private readonly string _modalId;
  12. private static IJSRuntime _jsRuntime;
  13. public static void Initialize(IJSRuntime jsRuntime)
  14. {
  15. _jsRuntime = jsRuntime;
  16. }
  17. public ModalHelper(string modalId)
  18. {
  19. _modalId = modalId;
  20. }
  21. public async void Show()
  22. {
  23. if (_jsRuntime != null)
  24. {
  25. await _jsRuntime.InvokeVoidAsync("eval", $"$('#{_modalId}').modal('show')");
  26. }
  27. }
  28. public async void Hide()
  29. {
  30. if (_jsRuntime != null)
  31. {
  32. await _jsRuntime.InvokeVoidAsync("eval", $"$('#{_modalId}').modal('hide')");
  33. }
  34. }
  35. }
  36. }