Data selected from list does not go to other page

Viewed 44

First of all my codes:

Index.cshtml:

@using ToDoListApp.Models
@model List<TodoTable>

<br />
<div class="p-3 mb-2 bg-dark text-white">All Tasks</div>
<table class="table table-hover">
    <thead>
        <tr>
            <th scope="col">ID</th>
            <th scope="col">Task</th>
            <th scope="col">Urgent</th>
            <th scope="col">Done</th>
            <th scope="col">Transactions</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model) {
            <tr>
                <th scope="row">@item.Id</th>
                <td>@item.Name</td>
                <td>@(item.Urgent ? "Yes" : "No")</td>
                <td>@(item.Done ? "Yes" : "No")</td>
                <td>
                    <div class="dropdown">
                        <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
                            Transactions
                        </button>
                        <ul class="dropdown-menu" aria-labelledby="TransactionsMenu">
                            <li>
                                <a class="dropdown-item" href="/TodoTables/Urgent/@item.Id">@(item.Urgent ? "Unurgent" : "Urgent")</a>
                            </li>
                            <li><a class="dropdown-item" href="#">@(item.Done ? "Undone" : "Done")</a></li>
                        </ul>
                    </div>
                </td>
            </tr>
        }
    </tbody>
</table>

Controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ToDoListApp.Models;

namespace ToDoListApp.Controllers
{
    public class TodoTablesController : Controller
    {
        TodolistContext db = new TodolistContext();
        [HttpGet]
        public IActionResult Index()
        {
            var Result = db.TodoTables.ToList();
            return View(Result);
        }
        [HttpGet]
        public ActionResult Urgent(int Id)
        {
            var Task = db.TodoTables.SingleOrDefault(i => i.Id == id);
            return View("Urgent", Task);
        }
    }
}

When I click on the item I selected from the table in Index.cshtml, I want the data to appear on the other page. The other page to show the given is:

Urgent.cshtml:

@model ToDoListApp.Models.TodoTable

@Html.LabelFor(m => m.Name);
@Html.LabelFor(m => m.Id);

How can I solve the problem?

0 Answers
Related