我得到的错误在我的MVC 5应用程序:MVC IPagedList与模型类型的错误
CS1061:“IPagedList”不包含“TargetContact”,没有扩展方法的定义“TargetContact”接受一个类型的第一个参数“IPagedList”可以找到(是否缺少using指令或程序集引用?)
我看到的答案在这里,但我还是不把它做:( 这可能是很容易解决的。
public ActionResult Index(string searchTargetContact = null, int page = 1)
{
var model =
from r in db.Outreach
orderby r.TargetContact descending
where (r.TargetContact.StartsWith(searchTargetContact) || searchTargetContact == null)
select new Models.OutreachSetListViewModel
{
TargetContact = r.TargetContact,
NextOutreachStep = r.NextOutreachStep,
GoalOfOutreach = r.GoalOfOutreach,
};
model.ToPagedList(page, 10);
return View(model);
namespace WebApplication11.Models
{
public class OutreachSetListViewModel
{
public string NextOutreachStep { get; set; }
public string TargetContact { get; set; }
public string GoalOfOutreach { get; set; }
}
}
@model IPagedList<OutreachSetListViewModel>
<table class="table" id="networkingList">
<tr>
<th>@Html.DisplayNameFor(model => model.TargetContact)</th>
<th>@Html.DisplayNameFor(model => model.NextOutreachStep)</th>
<th>@Html.DisplayNameFor(model => model.GoalOfOutreach)</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.TargetContact)</td>
<td>@Html.DisplayFor(modelItem => item.NextOutreachStep)</td>
<td>@Html.DisplayFor(modelItem => item.GoalOfOutreach)</td>
</tr>
}
谢谢!现在它识别属性,但我得到以下错误:传入字典的模型项目类型为'System.Data.Entity.Infrastructure.DbQuery'1 [WebApplication11.Models.OutreachSetListViewModel]',但该字典需要模型项目类型'PagedList.IPagedList'1 [WebApplication11.Models.OutreachSetListViewModel]'。' – user2675973
更新我的回应。 –
就是这样!!!!!谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! – user2675973