我得到的錯誤在我的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