【问题标题】:@Url.RouteUrl returns empty string@Url.RouteUrl 返回空字符串
【发布时间】:2012-07-20 10:03:35
【问题描述】:

请问有人对此有什么建议吗? Mvc3 不会从以下返回我的路由 url。我做了一些非常相似的事情并且它有效。这两条路线都不会因任何可选参数或任何东西而变得复杂,它真的非常简单。到底是怎么回事?

这是在我的 global.asax.cs...

routes.Add("StateProductRoute", 
    new Route("{state}"+locationUrlLiteralPart+"/{productName}-{productType}", 
        new CustomUrlRouteHandler(CustomUrlRouteHandlerUsageType.Product))
        {
            Constraints = new RouteValueDictionary
            {
                { "constraint1", new ProductConstraint() }
            } 
        });

...这在我看来...

<a href="@Url.RouteUrl("StateProductRoute", 
    new { state="archer", productName="hello", productType="goodbye"})" 
    class="media">

【问题讨论】:

  • 顺便说一句,如果它有什么不同,我渲染这个链接的视图是由另一个控制器调用的,而不是处理 StateProductRoute 的控制器
  • locationUrlLiteralPart 是什么?
  • 它实际上只是我们想要在 url 中的一个字符串。我有一堆位于美国位置的产品,网址可能是 mysite.com/colorado-holidays/thebeach-hotel

标签: c# asp.net-mvc asp.net-mvc-3 model-view-controller routing


【解决方案1】:

是否缺少破折号?

new Route("{state}**-**"+locationUrlLiteralPart+"/{productName}-{productType}", 

【讨论】:

  • 这没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
  • 在我看来,在 {state} 之后插入破折号应该可以解决问题。这并不是要批评。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-27
  • 2020-07-11
  • 2015-05-25
  • 2011-05-09
  • 1970-01-01
  • 2011-12-15
  • 2020-11-23
相关资源
最近更新 更多