使用分页时ASP.NET MVC错误的生成URL [英] ASP.NET MVC incorect generation url when using pagination
本文介绍了使用分页时ASP.NET MVC错误的生成URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须同意
[HttpGet]
[Route("{forumName}", Order = 8)]
[Route("{forumName}/Page/{page}", Order = 7)]
[OutputCache(Duration = 30, VaryByParam = "forumName;page", Location = OutputCacheLocation.ServerAndClient)]
public async Task<ActionResult> ShowForum(string forumName, int page = 1)
和
[HttpGet]
[RefreshDetectFilter]
[Block(VisibleBlock = false)]
[Route("~/Forums/{forum}/{topicName}", Order = 6)]
[Route("~/Forums/{forum}/{topicName}/Page/{page}", Order = 5)]
[OutputCache(Duration = 30, VaryByParam = "topicName;page", Location = OutputCacheLocation.ServerAndClient)]
public async Task<ActionResult> ShowTopic(string forum, string topicName, int page = 1)
剃刀
<a href="@Url.Action("ShowForum", "Forums", new {forumName = Model.NameTranslit})" title="@Model.Name">@Model.Name</a>
和
<a href="@Url.Action("ShowTopic", "Forums", new { forum = Model.CurrentForumTranslite, topicName = Model.TitleTranslite })" title="@Model.Title">@Model.Title</a>
当我在带有示例的页面上
When I at page with example this
/ Forums / Test / Page / 2
链接到子论坛我有正常链接,但链接到我在页面上拥有的主题
Link to the sub forum I have normal link, but link to the topic I have with page
/ Forums / Test / Test_Topic / Page / 2
但是应该
/ Forums / Test / Test_Topic
我的理解。我有这个错误,因为在我的操作中,我的页面具有相同的路由参数
How I understand. I have this bug because in my actions I have the same route parameter for page
我该怎么做才能解决此问题?
What I should to do to fix that?
推荐答案
我发现了解决该问题的方法
I found how the workaround the problem
对于ShowTopic路线
For route ShowTopic
[Route("~/Forums/{forum}/{topicName}", Order = 6)]
我添加了名字
[Route("{forum}/{topicName}", Name = "showTopic", Order = 6)]
并在以下网址获取网址主题,我正在使用Url.RouteUrl
And for get url at topic, I'm using Url.RouteUrl
<a href="@Url.RouteUrl("showTopic", new { forum = Model.CurrentForumTranslite, topicName = Model.TitleTranslite })" title="@Model.Title">@Model.Title</a>
这篇关于使用分页时ASP.NET MVC错误的生成URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文