如何解决此 asp.net mvc 路由问题 - 删除首页的页面(可选)?

发布于 2024-12-12 21:58:25 字数 618 浏览 5 评论 0原文

如何强制 URL 首页没有页码? 这是我使用的确切代码。

routes.MapRoute("MyPictureQuotes",
                "picture-quotes/{PictureQuotesPage}", 
                new { controller = "Quote", action = "PictureQuotes", PictureQuotesPage = UrlParameter.Optional }
            );

<%= Html.RouteLink("Picture Quotes", "MyPictureQuotes", null, new { title = "Picture Quotes", PictureQuotesPage = string.Empty })%>

它回来了 “/picture-quotes/5”而不是
页面中的“/picture-quotes”
"http://localhost:2489/picture-quotes/5"

看来第5页的路由值被结转了。

有人有解决方案吗?

How can I force URL first page without page number?
Here is the exact code I use.

routes.MapRoute("MyPictureQuotes",
                "picture-quotes/{PictureQuotesPage}", 
                new { controller = "Quote", action = "PictureQuotes", PictureQuotesPage = UrlParameter.Optional }
            );

<%= Html.RouteLink("Picture Quotes", "MyPictureQuotes", null, new { title = "Picture Quotes", PictureQuotesPage = string.Empty })%>

It returns
"/picture-quotes/5" instead of
"/picture-quotes" from the page
"http://localhost:2489/picture-quotes/5"

It seems the routing value page 5 is carried over.

Does anyone have a solution for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2024-12-19 21:58:26

您没有使用 Html.RouteLink 的正确重载。使用以下内容:

<%= Html.RouteLink("Picture Quotes", "MyPictureQuotes", 
    new { PictureQuotesPage = string.Empty }, 
    new { title = "Picture Quotes" })%>

You are not using the correct overload of Html.RouteLink. Use the following:

<%= Html.RouteLink("Picture Quotes", "MyPictureQuotes", 
    new { PictureQuotesPage = string.Empty }, 
    new { title = "Picture Quotes" })%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文