| 123456789101112131415161718192021222324252627282930313233343536373839 |
- @model bitforum.Constants.Menu;
- @inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
- @{
- // 현재 요청 경로 가져오기
- var currentPath = HttpContextAccessor.HttpContext?.Request?.Path.ToString()?.TrimEnd('/');
- // 고정된 메뉴 경로
- var menuPath = (Model.Path?.TrimEnd('/') ?? string.Empty);
- // 활성화 여부 확인
- var isActive = !string.IsNullOrEmpty(currentPath) && !string.IsNullOrEmpty(menuPath) &&
- (currentPath.Equals(menuPath, StringComparison.OrdinalIgnoreCase) ||
- currentPath.StartsWith(menuPath + "/", StringComparison.OrdinalIgnoreCase) ||
- menuPath.StartsWith(currentPath + "/", StringComparison.OrdinalIgnoreCase));
- }
- <li class="nav-item">
- <a href="@Model.Path" class="nav-link @(isActive ? "active" : "")"
- @Html.Raw(Model.Children != null && Model.Children.Any() ? "data-bs-toggle=\"collapse\"" : "")
- @Html.Raw(Model.Children != null && Model.Children.Any() ? $"data-bs-target=\"#menu-{Model.Id}\"" : "")
- >
- @if (!string.IsNullOrEmpty(Model.Icon))
- {
- @Html.Raw(Model.Icon);
- }
- @Model.Name
- </a>
- @if (Model.Children != null && Model.Children.Any())
- {
- <ul id="menu-@Model.Id" class="nav flex-column flex-nowrap ps-3 collapse">
- @foreach (var child in Model.Children)
- {
- @Html.Partial("_MenuItem", child);
- }
- </ul>
- }
- </li>
|