DataPager控件使用Sitecore布局URL而不是项URL

DataPager控件使用Sitecore布局URL而不是项URL,sitecore,sitecore6,datapager,Sitecore,Sitecore6,Datapager,为了在Sitecore 6.3.1站点上实现搜索结果页面,我在/Sitecore/content/Home/search中创建了一个内容项,并将搜索结果子布局添加到其显示控件中。子布局使用ListView显示搜索结果,使用DataPager处理分页 以下是Search Results.ascx的摘录: 请注意,DataPager的QueryStringField参数设置为非空值 呈现子布局时,搜索结果和分页控件将正确显示。但是,分页超链接指向错误的URL。它们不会转到页面URL,而是链接到布局的

为了在Sitecore 6.3.1站点上实现搜索结果页面,我在/Sitecore/content/Home/search中创建了一个内容项,并将搜索结果子布局添加到其显示控件中。子布局使用ListView显示搜索结果,使用DataPager处理分页

以下是Search Results.ascx的摘录:

请注意,DataPager的QueryStringField参数设置为非空值

呈现子布局时,搜索结果和分页控件将正确显示。但是,分页超链接指向错误的URL。它们不会转到页面URL,而是链接到布局的URL

例如,如果用户单击第2页的链接,人们会期望他的浏览器转到,例如。但他的浏览器实际上链接到了


DataPager从哪里获得虚假URL?我该如何修复此问题?

我想这是因为DataPager只使用标准asp.net URL,不知道Sitecore或Sitecore创建URL的方式


我认为您必须以另一种方式来完成这项工作,即使用一个简单的中继器或创建一个使用Sitecore.Links.LinkManager.GetItemUrlSitecore.Context.Item的DataPager;作为链接的基础。

我想这是因为DataPager只使用标准的asp.net URL,不知道Sitecore或Sitecore创建URL的方式


我认为您必须以另一种方式来完成这项工作,即使用一个简单的中继器或创建一个使用Sitecore.Links.LinkManager.GetItemUrlSitecore.Context.Item的DataPager;作为链接的基础。

以下是我最终采用的解决方案。这并不漂亮,但确实有效:

/// <summary> /// Fixes any HyperLinks that point to the layout .aspx file to point to /// the Sitecore context item. /// </summary> /// <param name="control"> /// The control to fix (its child controls will be processed). /// </param> protected void FixLayoutHyperLinks(Control control) { var currentPath = LinkManager.GetItemUrl(Sitecore.Context.Item); foreach (Control c in control.Controls) { foreach (Control d in c.Controls) { if (d is HyperLink) { var link = (HyperLink)d; /* Change just the path of the existing URL. * @see http://stackoverflow.com/questions/5276324/modifying-just-the-path-part-of-a-hyperlinks-navigateurl-in-c/5276375#5276375 */ var url = new UriBuilder(Request.Url.Host + link.NavigateUrl); url.Path = currentPath; /* For consistency (and because ASP.Net will strip the leading * "http://" during PreRender), do not add the hostname/schema to * the resulting URI. * * @see http://sobot-software.blogspot.com/2009/02/asphyperlink-navigateurl-problem.html */ link.NavigateUrl = url.Uri.PathAndQuery; } } } } 我这样使用它:

private void Page_Load(object sender, EventArgs e) { ... var Pager = MyListView.FindControl("Pager") as DataPager; FixLayoutHyperLinks(Pager); }
这是我最终采用的解决方案。这并不漂亮,但确实有效:

/// <summary> /// Fixes any HyperLinks that point to the layout .aspx file to point to /// the Sitecore context item. /// </summary> /// <param name="control"> /// The control to fix (its child controls will be processed). /// </param> protected void FixLayoutHyperLinks(Control control) { var currentPath = LinkManager.GetItemUrl(Sitecore.Context.Item); foreach (Control c in control.Controls) { foreach (Control d in c.Controls) { if (d is HyperLink) { var link = (HyperLink)d; /* Change just the path of the existing URL. * @see http://stackoverflow.com/questions/5276324/modifying-just-the-path-part-of-a-hyperlinks-navigateurl-in-c/5276375#5276375 */ var url = new UriBuilder(Request.Url.Host + link.NavigateUrl); url.Path = currentPath; /* For consistency (and because ASP.Net will strip the leading * "http://" during PreRender), do not add the hostname/schema to * the resulting URI. * * @see http://sobot-software.blogspot.com/2009/02/asphyperlink-navigateurl-problem.html */ link.NavigateUrl = url.Uri.PathAndQuery; } } } } 我这样使用它:

private void Page_Load(object sender, EventArgs e) { ... var Pager = MyListView.FindControl("Pager") as DataPager; FixLayoutHyperLinks(Pager); }
这个问题现在也在SDN论坛上。SDN上的另一个帖子似乎对此有一个解决方案-这个问题现在也在SDN论坛上。SDN上的另一个帖子似乎对此有一个解决方案-感谢您的建议。我想这是我必须走的路。SDN上的一张海报建议我寻找一种定制分页链接呈现方式的方法。谢谢你的建议。我想这是我必须走的路。SDN上的一张海报建议我寻找一种定制分页链接呈现方式的方法;使用递归太慢了,但我需要更深入,而不仅仅是1级;使用递归太慢了,但我需要更深入一层。