将@ Html.DisplayNameFor()与PagedList一起使用 [英] Using @Html.DisplayNameFor() with PagedList

查看:123
本文介绍了将@ Html.DisplayNameFor()与PagedList一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试PagedList包来获取索引视图的分页.一切进展顺利,在控制器级别上一切正常,每页仅显示5条记录,并根据查询字符串显示适当的页面.

I've been trying out the PagedList package to get paging for my index views. Everything was going well, and at the controller level everything is working fine, it only displays 5 records per page, and displays the appropriate page based on the querystring.

我的问题在视图中.我将@Model更改为PagedList.IPagedList,以便可以访问Model.HasNextPage和其他属性,但是现在@Html.DisplayNameFor(model => model.ItemName)不再起作用.我收到此错误:

My problem is in the view. I changed the @Model to PagedList.IPagedList so I could access the Model.HasNextPage and other properties, but now the @Html.DisplayNameFor(model => model.ItemName) are no longer working. I get this error:

PagedList.IPagedList<Dossier.Models.Item>' does not contain a definition for 'ItemName' and no extension method 'ItemName' accepting a first argument of type 'PagedList.IPagedList<Dossier.Models.Item>' could be found (are you missing a using directive or an assembly reference?)

以下是视图的相关部分:

Here are the relevant parts of the view:

@model PagedList.IPagedList<Dossier.Models.Item>
@using Dossier.Models.Item

...

<th>
    @Html.DisplayNameFor(model => model.ItemName)
</th>

似乎IPagedList与DisplayNameFor()不兼容.知道为什么会发生这种情况以及如何解决吗?我知道我可以手动输入列名,但是我希望以后将这些信息保留在模型中(并可以更改).

It seems IPagedList is not compatible with DisplayNameFor(). Any idea why this is happening, and how I could fix it? I know I could just manually enter the column names, but I'd like for that information to stay (and be changeable) in the model later.

推荐答案

您可以尝试

@Html.DisplayNameFor(model => model.FirstOrDefault().ItemName)

这篇关于将@ Html.DisplayNameFor()与PagedList一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆