如何使用 MVCContrib 和 Razor 制作寻呼机?
我有一个寻呼机,如下所示:
@using MvcContrib.UI.Pager
@model MvcContrib.Pagination.IPagination
<p/>
@Html.Pager(Model).First("First").Last("Last").Next("Next").Previous("Previous")
<p/>
而不是显示此内容:
显示 1 - 10 共 10841 条 上一页 |下一页 | 最后的
它显示:
<div class='pagination'><span class='paginationLeft'>Showing 1 - 10 of 10841 </span><span class='paginationRight'>First | Previous | <a href="/Home/Events?page=2">Next</a> | <a href="/Home/Events?page=1085">Last</a></span></div>
我还从 codeproject 下载了一个示例项目,但是当我运行它时,我遇到了同样的问题。
可能是什么问题?你们能帮我一下吗?
I have a pager as follows:
@using MvcContrib.UI.Pager
@model MvcContrib.Pagination.IPagination
<p/>
@Html.Pager(Model).First("First").Last("Last").Next("Next").Previous("Previous")
<p/>
Instead of displaying this:
Showing 1 - 10
of 10841 First |
Previous | Next |
Last
It displays this:
<div class='pagination'><span class='paginationLeft'>Showing 1 - 10 of 10841 </span><span class='paginationRight'>First | Previous | <a href="/Home/Events?page=2">Next</a> | <a href="/Home/Events?page=1085">Last</a></span></div>
I also downloaded a sample project from codeproject, but when I run it, I get the same problem.
What could possibly be the problem? Can you guys help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您返回字符串,Razor 会自动对 html 进行编码。如果您返回 IHtmlString,它不会对 Html 进行编码。
寻呼机方法是否返回 String 而不是 IHtmlString?
尝试使用 Html.Raw。此方法会将 String 转换为 IHtmlString。
Razor automatically encodes html if you return a String. It won't encode Html if you return an IHtmlString.
Does the pager method return a String instead of IHtmlString?
Try using Html.Raw. This method will convert a String to an IHtmlString.
它在示例项目而不是您的项目中工作的原因是因为在示例项目中,他们在部分页面中使用
@Html.Pager
,然后使用在主页上调用该部分页面@{Html.RenderPartial();}
当像这样渲染时,来自Pager
的渲染字符串将输出为 html 而不是编码的 html。如果您需要使用没有子页面的分页器,那么您需要按照 Linkgoron 的建议将调用包装在
Html.Raw
中,因为Html.Pager
默认使用 < code>ToString 返回一个string
而不是IHtmlString
The reason it works in the sample project and not your project is because in the sample project they're using the
@Html.Pager
in a partial page which is then called on the main page using@{Html.RenderPartial();}
when rendering like that the rendered string from thePager
is output as html rather than encoded html.If you need to use the pager without the subpages then you'll need to wrap the call in
Html.Raw
as Linkgoron suggested as theHtml.Pager
defaults to using theToString
which returns astring
and notIHtmlString