_Header.cshtml 1022 B

123456789101112131415161718192021222324252627282930313233
  1. @{
  2. var boardID = ViewData["BoardID"];
  3. var boardList = ViewData["BoardList"] as List<(int ID, string Name)>;
  4. }
  5. <div class="row">
  6. <div class="col">
  7. <h3>@ViewData["Title"]</h3>
  8. </div>
  9. <div class="col-auto">
  10. <select id="boardSelect" class="form-select">
  11. <option value="">게시판 선택</option>
  12. @if (boardList != null)
  13. {
  14. @foreach (var (id, name) in boardList)
  15. {
  16. <option value="@id" selected="@(id == (int?)boardID)">@name</option>
  17. }
  18. }
  19. </select>
  20. </div>
  21. </div>
  22. <hr />
  23. <script type="module">
  24. document.getElementById("boardSelect")?.addEventListener("change", function() {
  25. if (this.value) {
  26. const path = window.location.pathname;
  27. const segments = path.split('/');
  28. segments[segments.length - 1] = this.value;
  29. window.location.href = segments.join('/') + window.location.search;
  30. }
  31. });
  32. </script>