PagedList.IPaged<ProjectName.WebUI.Model>不包含配置文件的定义(您是否缺少 using 指令或引用
PagedList.IPaged<ProjectName.WebUI.Model>does not contain a definition for Profiles(are you missing ising directive or refrence
我是 Asp.net 的新人,我有一个错误
我在我的项目中使用 Pagedlist 和 ViewModel
实现了存储库模式
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoboAnimal.Domain.Entities
{
public class Profile
{
public int ProfileID { get; set; }
public string Color { get; set; }
public string Image { get; set; }
public string PlaceHolder { get; set; }
public DateTime? DateOfPubl { get; set; }
public string CurrentCategory { get; set; }
}
}
我的 ViewModel class 和控制器:
using System.Collections.Generic;
using HoboAnimal.Domain.Entities;
using PagedList.Mvc;
using PagedList;
namespace HoboAnimal.WebUI.Models
{
public class ProfilesListViewModel
{
public PagedList.IPagedList<Profile> Profiles {get; set;}
}
}
和视图:
@model PagedList.IPagedList<HoboAnimal.WebUI.Models.ProfilesListViewModel>
@using PagedList.Mvc;
@using HoboAnimal.WebUI.Models
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Profiles";
}
@foreach (var p in Model.Profiles)
{
<h2>@p.Image</h2>
<h3>@p.DateOfPubl</h3>
<h2>@p.CurrentCategory</h2>
}
Страница @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) из @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
我在这条车道上有错误:
@foreach (var p in Model.Profiles)
PagedList.IPagedList'
does not contain a definition for 'Profiles' and no extension method
'Profiles' accepting a first argument of type
'PagedList.IPagedList'
could be found (are you missing a using directive or an assembly
reference?)
我不知道如何修复它,我尝试在我的模型中添加 @using 指令但它没有帮助
谢谢你
PagedList 应该在类似于此的地方实现。无需为 PagedList 创建视图模型。
控制器
using PagedList;
public ViewResult Index(int? page)
{
var profiles = db.Profiles.ToList();
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(profiles.ToPagedList(pageNumber, pageSize));
}
查看
@model PagedList.IPagedList<HoboAnimal.WebUI.Models.ProfilesListViewModel>
@using PagedList.Mvc;
@using HoboAnimal.WebUI.Models
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Profiles";
}
@foreach (var p in Model)
{
<h2>@p.Image</h2>
<h3>@p.DateOfPubl</h3>
<h2>@p.CurrentCategory</h2>
}
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page }))
我是 Asp.net 的新人,我有一个错误 我在我的项目中使用 Pagedlist 和 ViewModel
实现了存储库模式using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoboAnimal.Domain.Entities
{
public class Profile
{
public int ProfileID { get; set; }
public string Color { get; set; }
public string Image { get; set; }
public string PlaceHolder { get; set; }
public DateTime? DateOfPubl { get; set; }
public string CurrentCategory { get; set; }
}
}
我的 ViewModel class 和控制器:
using System.Collections.Generic;
using HoboAnimal.Domain.Entities;
using PagedList.Mvc;
using PagedList;
namespace HoboAnimal.WebUI.Models
{
public class ProfilesListViewModel
{
public PagedList.IPagedList<Profile> Profiles {get; set;}
}
}
和视图:
@model PagedList.IPagedList<HoboAnimal.WebUI.Models.ProfilesListViewModel>
@using PagedList.Mvc;
@using HoboAnimal.WebUI.Models
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Profiles";
}
@foreach (var p in Model.Profiles)
{
<h2>@p.Image</h2>
<h3>@p.DateOfPubl</h3>
<h2>@p.CurrentCategory</h2>
}
Страница @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) из @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
我在这条车道上有错误:
@foreach (var p in Model.Profiles)
PagedList.IPagedList' does not contain a definition for 'Profiles' and no extension method 'Profiles' accepting a first argument of type 'PagedList.IPagedList' could be found (are you missing a using directive or an assembly reference?)
我不知道如何修复它,我尝试在我的模型中添加 @using 指令但它没有帮助 谢谢你
PagedList 应该在类似于此的地方实现。无需为 PagedList 创建视图模型。
控制器
using PagedList;
public ViewResult Index(int? page)
{
var profiles = db.Profiles.ToList();
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(profiles.ToPagedList(pageNumber, pageSize));
}
查看
@model PagedList.IPagedList<HoboAnimal.WebUI.Models.ProfilesListViewModel>
@using PagedList.Mvc;
@using HoboAnimal.WebUI.Models
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Profiles";
}
@foreach (var p in Model)
{
<h2>@p.Image</h2>
<h3>@p.DateOfPubl</h3>
<h2>@p.CurrentCategory</h2>
}
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page }))