ASP.NET MVC 中的模型缺少定义错误

Model Missing Definition Error in ASP.NET MVC

我一直在尝试使用 ASP.NET MVC 创建一个简单的 Bootstrap Table,它从数据库中提取所有记录,但我无法弄清楚为什么会出现错误:

CS1061: Model does not contain a definition for 'Count' and no accessible extension method 'Count' accepting a first argument of type Model could be found

我的模特:

public class AdminModel
{
    [Display(Name = "Admin ID")]
    public int AdminID { get; set; }

    [Display(Name = "User Id")]
    [Required]
    public string UserName { get; set; }

    [Display(Name = "First Name")]
    [Required]
    public string FirstName { get; set; }

    [Display(Name = "Last Name")]
    [Required]
    public string LastName { get; set; }

    [Display(Name = "Password")]
    [Required]
    public string Password { get; set; }
}

我的看法:

@model RuciyanaSweets.Models.AdminModel

<div class="table-responsive">
    <table class="table">
        @if (Model.Count() == 0)
        {
            <tr>
                <td colspan="10">No Record's found.</td>
            </tr>

        }
        Else
<show the table>
        </table>
</div>

我的控制:

public ActionResult AdminList()
{
    List<AdminModel> qry = new List<AdminModel>();

    using (dbEntities dm = new dbEntities ())
    {
        qry = (from data in dm.AdminTables select new AdminModel
               {
                   AdminID = data.AdminId,
                   UserName = data.UserName,
                   FirstName = data.FirstName,
                   LastName = data.LastName
               }).ToList();
    }

    return View(qry);
}

谁能告诉我哪里出错了?我想不通。

您正在将 AdminModel 的集合传递给视图。因此使用以下模型定义:

@model IEnumerable<AdminModel>

Enumerable.Count Method