Guest User

Untitled

a guest
Oct 7th, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. @model Models.ViewModels.TodoViewModel
  2.  
  3. @{
  4. ViewData["Title"] = "To-do App";
  5. }
  6.  
  7. <form asp-action="Insert" method="post" id="forms">
  8. <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  9. <div class="form-group" id="createform">
  10. <label asp-for="Todo.Name">To do name</label>
  11. <input type="text" asp-for="Todo.Name" class="form-control" id="todoname" placeholder="Enter your to do's name">
  12. <span asp-validation-for="Todo.Name" class="text-danger"></span>
  13. </div>
  14. <div class="form-group">
  15. <input type="submit" value="Create" id="submitbutton" style="margin: 1em 0px 1em 0px;" class="btn btn-success" />
  16. </div>
  17. </form>
  18.  
  19. <div class="todolist">
  20. <ul id="todolist">
  21. @foreach (var todo in Model.TodoList)
  22. {
  23. <li class="listitems">
  24. @todo.Name
  25. <a asp-action="Delete" asp-route-id="@todo.Id" method="post" class="btn btn-danger">Delete</a>
  26. <a onclick="showUpdateInput('@todo.Id')" class="btn btn-primary">Update</a>
  27. <form asp-action="Update" method="post" class="updateformbutton" id="[email protected]" style="display: none;">
  28. <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  29. <input type="text" asp-for="Todo.Name" id="updatetodoinput" style="margin-left: 15px;" />
  30. <span asp-validation-for="Todo.Name" class="text-danger"></span>
  31. <input type="hidden" asp-for="Todo.Id" value="@todo.Id">
  32. <input type="submit" value="Update" />
  33. </form>
  34. </li>
  35. }
  36. </ul>
  37. </div>
  38.  
  39. @section Scripts{
  40.  
  41. <script>
  42. const createButton = document.getElementById("create");
  43. const forms = document.querySelector("#forms");
  44. const updateForm = document.querySelector(".updateform");
  45. const submitButton = document.querySelector("#submitbutton");
  46. const updateButton = document.getElementById("updatebutton");
  47. const todoList = document.getElementById("todolist");
  48. const createTodoInput = document.getElementById("todoname")
  49.  
  50. createTodoInput.value = "";
  51.  
  52. document.querySelector(".updateformbutton")
  53.  
  54. let previousFormId = null;
  55.  
  56. function showUpdateInput(todoId){
  57. if (previousFormId) {
  58. document.getElementById(previousFormId).style.display = "none";
  59. }
  60.  
  61. var updateForm = document.getElementById("updateform_" + todoId);
  62. updateForm.style.display = "block";
  63.  
  64. previousFormId = "updateform_" + todoId;
  65. }
  66. </script>
  67. }
Advertisement
Add Comment
Please, Sign In to add comment