繁体   English   中英

ASP.NET MVC - 无法访问 model

[英]ASP.NET MVC - Unable to access model

我正在制作一个页面,这个页面有表格。 我正在尝试在表中创建一个过滤系统。 我做了过滤系统,但我遇到了问题。

首先我的代码:

`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>

我遇到了这个问题:

在此处输入图像描述

我怎么解决这个问题? 在此先感谢您的帮助。

您的@model StudentApp.Models.Entity.StudentTable必须是您的 Index.cshtml 中的@model List<StudentApp.Models.Entity.StudentTable>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM