_Header.cshtml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. @using Library.Models.Forum
  2. @{
  3. var boardID = ViewData["BoardID"] as int?;
  4. var boardList = ViewData["BoardList"] as List<Board>;
  5. }
  6. <div class="row">
  7. <div class="col">
  8. <h3>@ViewData["Title"]</h3>
  9. </div>
  10. <div class="col-auto">
  11. <select id="boardID" class="form-select" required>
  12. <option value="">게시판 선택</option>
  13. @if (boardList != null)
  14. {
  15. @foreach (var row in boardList)
  16. {
  17. <option value="@row.ID" selected="@(row.ID == boardID)">@row.Name</option>
  18. }
  19. }
  20. </select>
  21. </div>
  22. </div>
  23. <hr />
  24. <script type="module">
  25. $(document).on("change", "#boardID", function () {
  26. var boardID = $(this).val();
  27. if (boardID) {
  28. const url = new URL(window.location.href);
  29. const pathSegments = url.pathname.split('/');
  30. if (pathSegments.length >= 6) {
  31. pathSegments[5] = boardID;
  32. }
  33. const newPath = pathSegments.join('/');
  34. const newURL = `${newPath}${url.search}`;
  35. window.location.href = newURL;
  36. }
  37. });
  38. </script>