DataPager 和 ASP.NET 页面路由的 QueryStringField?
我正在使用 DataPager 的 QueryStringField 在 url 中显示页码。工作罚款。 但我不希望字段名称显示在网址中。我厌倦的是
全局文件代码:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("xyz", "Test/TestRoutes/{PageId}", "~/Demo1.aspx", true, new RouteValueDictionary { { "PageId", "1" } });
}
并且在我为DataPager编写的html中。
<asp:DataPager ID="ProductListPagerComboTop" runat="server" PagedControlID="lv1"
PageSize="5" QueryStringField="PageId">
<Fields>
<asp:NextPreviousPagerField RenderNonBreakingSpacesBetweenControls="false" ButtonCssClass="pagerButton"
FirstPageText="<<" ShowFirstPageButton="True" ShowNextPageButton="False" />
<asp:NumericPagerField CurrentPageLabelCssClass="pagerButtonCurrentPage" RenderNonBreakingSpacesBetweenControls="false"
NextPreviousButtonCssClass="pagerButton" NumericButtonCssClass="pagerButton" />
<asp:NextPreviousPagerField RenderNonBreakingSpacesBetweenControls="false" ButtonCssClass="pagerButton"
LastPageText=">>" ShowLastPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
所以生成的网址是:
http://localhost:2055/Test/TestRoutes?PageId=2
我想要的地方。
http://localhost:2055/Test/TestRoutes/2
如何做到这一点?
I am using QueryStringField to of DataPager to show page number in url. Work fines.
But i don't want the name of field to be shown in url. what i tired is
Global File Code:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("xyz", "Test/TestRoutes/{PageId}", "~/Demo1.aspx", true, new RouteValueDictionary { { "PageId", "1" } });
}
and in html i wrote for DataPager.
<asp:DataPager ID="ProductListPagerComboTop" runat="server" PagedControlID="lv1"
PageSize="5" QueryStringField="PageId">
<Fields>
<asp:NextPreviousPagerField RenderNonBreakingSpacesBetweenControls="false" ButtonCssClass="pagerButton"
FirstPageText="<<" ShowFirstPageButton="True" ShowNextPageButton="False" />
<asp:NumericPagerField CurrentPageLabelCssClass="pagerButtonCurrentPage" RenderNonBreakingSpacesBetweenControls="false"
NextPreviousButtonCssClass="pagerButton" NumericButtonCssClass="pagerButton" />
<asp:NextPreviousPagerField RenderNonBreakingSpacesBetweenControls="false" ButtonCssClass="pagerButton"
LastPageText=">>" ShowLastPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
So the url generated is :
http://localhost:2055/Test/TestRoutes?PageId=2
where as i want.
http://localhost:2055/Test/TestRoutes/2
How to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 IIS 上的 URL 重写模块。
You can use the URL Rewrite module on the IIS.
您尝试在此处重写您的 URL。
ScottG's Blog 最好理解这个概念。
请参阅以下 URL:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
You try re-writing your URL here.
ScottG'S Blog is best to understand this concept.
Refer below URL:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx