Untitled
unknown
plain_text
7 months ago
2.4 kB
2
Indexable
Never
@inject NavigationManager NavigationManager @rendermode InteractiveServer <button @onclick="NavigateToAccesslevels" class="btn btn-primary btn-lg">Edit Accesslevels</button> <ErrorModal @ref="_errorModal" ShowModal="@showErrorModal" ErrorMessage="@errorMessage" OnClose="HandleErrorModalClose" /> @code { [Parameter] public string Id { get; set; } [Parameter] public string UUID { get; set; } private ErrorModal _errorModal; private bool showErrorModal = false; private string errorMessage = ""; public void NavigateToAccesslevels() { try { CurrentUuid.SetCurrentUuid(UUID); NavigationManager.NavigateTo($"/edit-accesslevels/{Id}"); } catch (Exception ex) { HandleError("Sorry, we encountered an issue while navigating to access levels. Please check your connection and try again. If the problem persists, contact support for assistance."); } } private void HandleError(string message) { errorMessage = message; showErrorModal = true; _errorModal.ShowModal = true; } private void HandleErrorModalClose() { showErrorModal = false; } } <!-- ErrorModal.razor --> @inherits ComponentBase <div class="modal" tabindex="-1" role="dialog" style="display: @(ShowModal ? "block" : "none")"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Error</h5> <button type="button" class="close" @onclick="CloseModal"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> @ErrorMessage </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" @onclick="CloseModal">Ok</button> </div> </div> </div> </div> @code { [Parameter] public bool ShowModal { get; set; } [Parameter] public string ErrorMessage { get; set; } [Parameter] public EventCallback OnClose { get; set; } private void CloseModal() { ShowModal = false; OnClose.InvokeAsync(); } }
Leave a Comment