0

I am making a page and this page has Table. I'm trying to make a filtering system in Table. I made the filtering system, but I'm having problems.

First of all my codes:

`Index.cshtml`:

    @model List<StudentApp.Models.Entity.StudentTable>
@{
    ViewData["Title"] = "Manage Student";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
<h1>Manage Student</h1>
<br />
@using (Html.BeginForm("Index", "StudentTable", FormMethod.Get))
{
    <p>
         @Html.DropDownListFor(m => m.theErrorIsHere, (List<SelectListItem>)ViewBag.ClassT, new { @class = "form-control"})
        <b>Student Name:</b> @Html.TextBox("p");
        <input type="submit" value="Ara">
    </p>
}
<table id="tbl1" class="table table-bordered">
    <tr>
        <th>
            Student ID
        </th>
        <th>
            Student Name
        </th>
        <th>
            Student Class
        </th>
        <th>
            Edit
        </th>
        <th>
            Delete
        </th>
    </tr>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @item.Id
                </td>
                <td>
                    @item.Name
                </td>
                <td>
                    @item.Class.ClassName
                </td>
                <td>
                    <a href="/StudentTable/EditStudent/@item.Id" class="btn btn-success">Edit</a>
                </td>
                <td>
                    <a href="/StudentTable/Delete/@item.Id" class="btn btn-danger">Delete</a>
                </td>
            </tr>
        }
    </tbody>
</table>

<a href="/StudentTable/AddStudent"  class="btn btn-primary">Add Student</a>

And I am having this problem:

enter image description here

How can I solve this problem? Thanks in advance for your help.

1 Answer 1

2

your @model StudentApp.Models.Entity.StudentTable muste be @model List<StudentApp.Models.Entity.StudentTable> in your Index.cshtml

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for answers. Now I am getting an error like this: imgur.com/a/mQ9mF1E
i think you are inside the loop and need to get the class of a student. you can access the student by the 'item' property in the loop and get item.Class
Hello. I misplaced DropDownListFor. I should have put it outside the loop. I'm confused. Sorry. How can I use it outside of the loop? I updated the Index.cshtml codes in the topic. I would be glad if you help.
since this is another problem, better to create add this as a new Question on stackoverflow
I understand, sorry. So I'm opening a new topic.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.