HTML helper class method not working

ぐ巨炮叔叔 提交于 2019-12-06 01:17:43

You are passing a dynamic value to an extension method. (Hover over Model.PagingInfo and intellisense should tell you that the type is dynamic. This means it does not know what the type is until runtime) So, try changing your code so that it casts the dynamic type like this:

@Html.PageLinks((PagingInfo)Model.PagingInfo, x => Url.Action("List", new {page = x}))

You could fix this in two other ways:

As the error suggests, do not call it using the extension method:

PageLinks(Html, Model.PagingInfo, x => Url.Action("List", new {page = x}))

OR you could make the view know what the model is going to be so that it does not use a dynamic, by setting this at the top of your view

@model PagingInfo

you must add this lines in web.cofig under Views Folder not main one

  <add namespace="YourProjectName.HtmlHelpers"/>

Add @using project_name.HtmlHelpers e.g.

@using ChristianSchool.HtmlHelpers
@Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new { page = x, category = Model.CurrentCategory }))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!