【问题标题】:ASP.NET MVC incorect generation url when using pagination使用分页时 ASP.NET MVC 不正确的生成 url
【发布时间】:2016-11-04 04:17:04
【问题描述】:

我必须行动

    [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>

当我在页面上有这个例子时

/Forums/Test/Page/2

子论坛的链接我有正常的链接,但是链接到我有页面的主题

/Forums/Test/Test_Topic/Page/2

但应该是

/Forums/Test/Test_Topic

我是怎么理解的。我有这个错误是因为在我的操作中我有相同的页面路由参数

我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: asp.net razor routes


    【解决方案1】:

    我找到了解决问题的方法

    对于路线 ShowTopic

    [Route("~/Forums/{forum}/{topicName}", Order = 6)]
    

    我添加了名字

    [Route("{forum}/{topicName}", Name = "showTopic", Order = 6)]
    

    对于获取主题的 url,我使用的是 Url.RouteUrl

     <a href="@Url.RouteUrl("showTopic", new { forum = Model.CurrentForumTranslite, topicName = Model.TitleTranslite })" title="@Model.Title">@Model.Title</a>
    

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多