当我试图使用我的aspx文件时
@using PagedList.Mvc;
...
@Html.PagedListPager(ViewBag.test, page => Url.Action("Test", new { page })).
我会收到此错误消息
'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'PagedListPager' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
我的.cs文件代码看起来像这样
using PagedList;
private List<Quality> Qualitys()
{
List<Quality> Qualitys = new List<Quality>()
{
new Quality(){ID=1,Name="All Qualitys"},
new Quality(){ID=2,Name="1"},
new Quality(){ID=3,Name="2"},
new Quality(){ID=4,Name="3"},
new Quality(){ID=5,Name="4"},
new Quality(){ID=6,Name="5"}
};
return Qualitys;
}
public ActionResult Test(int? page)
{
int pageSize = 3;
int pageNumber = page ?? 1;
ViewBag.test = Qualitys().ToPagedList(pageNumber, pageSize);
return View();
}
在我的~Views / Web.config文件中,我会在那里。
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Web" />
</namespaces>
我无法理解为什么我会收到此错误,请帮忙。
答案 0 :(得分:6)
您需要将动态属性(在本例中为ViewBag.test
)转换为所需类型。它应该是
@Html.PagedListPager((IPagedList)ViewBag.test, page => Url.Action("Test", new { page }))