Ajax.Pager在MVC4中不起作用



我在MVC 2中使用Ajax。Pager,它运行良好。这是视图中的代码

<%= Ajax.Pager(new AjaxOptions { UpdateTargetId = ViewData.Model.UpdateTargetId, OnBegin = "beginPagings", OnSuccess = "successPagings", OnFailure = "failurePaging" },
        ViewData.Model.PageSize, ViewData.Model.PageNumber, ViewData.Model.TotalItemCount, new { controller = ViewContext.Controller.ControllerContext.RouteData.Values["Controller"], action = ViewContext.Controller.ControllerContext.RouteData.Values["action"], Id = ViewContext.Controller.ControllerContext.RouteData.Values["id"], str = ViewContext.Controller.ControllerContext.RouteData.Values["str"] })%>

这是AJax链接生成器代码

private MvcHtmlString GeneratePageLink(string linkText, int pageNumber)
        {
            var pageLinkValueDictionary = new RouteValueDictionary(this.linkWithoutPageValuesDictionary);
            pageLinkValueDictionary.Add("page", pageNumber);
            return ajaxHelper.ActionLink(linkText, pageLinkValueDictionary["action"].ToString(), pageLinkValueDictionary, ajaxOptions);
        }

但现在,当我升级到MVC 4时,并没有像预期的那样生成链接。

以下是我在视图中使用的MVC 4代码

@Ajax.Pager(new AjaxOptions { UpdateTargetId = Model.UpdateTargetId, OnBegin = "beginPagings", OnSuccess = "successPagings", OnFailure = "failurePaging" },
        Model.PageSize, Model.PageNumber, Model.TotalItemCount, new { controller = ViewContext.Controller.ControllerContext.RouteData.Values["Controller"], action = ViewContext.Controller.ControllerContext.RouteData.Values["action"], Id = ViewContext.Controller.ControllerContext.RouteData.Values["id"], str = ViewContext.Controller.ControllerContext.RouteData.Values["str"] })

但是生成的链接如下所示,它不再是一个链接。它呈现为纯文本。

<a data-ajax="true" data-ajax-begin="beginPagings" data-ajax-failure="failurePaging" data-ajax-mode="replace" data-ajax-success="successPagings" data-ajax-update="#divGrid" href="">2</a>

我偶然发现一篇文章说这是因为"不引人注目的Javascript"。我是不是错过了什么??

此问题可能与堆栈溢出中的类似问题有关

这是通过使用实现的

@Html.Raw()
@Html.Raw(Ajax.Pager(new AjaxOptions { UpdateTargetId = Model.UpdateTargetId, OnBegin = "beginPagings", OnSuccess = "successPagings", OnFailure = "failurePaging" },
        Model.PageSize, Model.PageNumber, Model.TotalItemCount, new { controller = ViewContext.Controller.ControllerContext.RouteData.Values["Controller"], action = ViewContext.Controller.ControllerContext.RouteData.Values["action"], Id = ViewContext.Controller.ControllerContext.RouteData.Values["id"], str = ViewContext.Controller.ControllerContext.RouteData.Values["str"] }))

现在,文本呈现为链接。。

贾斯汀的回答帮了我…谢谢贾斯汀。