I am stuck trying to create a simple Bootstrap Table with ASP.NET MVC that pulls all records from a database but I cannot figure out why I am getting the error:
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
My model:
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; }
}
My view:
@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>
My control:
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);
}
Can someone tell me where I am going wrong? I cannot figure it out.
CodePudding user response:
You are passing collection of the AdminModel
to the view. Therefore use the following model definition:
@model IEnumerable<AdminModel>