【问题标题】:mvc attribute based route with an optional first parameter基于 mvc 属性的路由,带有可选的第一个参数
【发布时间】:2015-09-09 12:53:51
【问题描述】:

我有这条路线:[Route("{country?}/mymessages")]

当我请求http://allthings.trade/australia/mymessages 时,路由工作正常。如果我尝试:http://allthings.trade/mymessages 路线未命中。

我认为它可能是中间的“/”,所以我将路线更改为下面,它没有任何区别: [Route("{country?}mymessages")]

任何想法,我怀疑第一个参数可能不是可选的吗?

谢谢各位。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-routing


    【解决方案1】:

    我认为这可能只是您不能在路线中间使用可选参数。不过我可能是错的。

    为什么不只有两条路线?

    [Route("{country}/mymessages")]
    [Route("mymessages")]
    public ActionResult MyAction(string country, string message){..}
    

    编辑: 我只是试图在本地运行,但因为我什至无法让你的工作,所以不能,更多代码?

    【讨论】:

      猜你喜欢
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 2014-04-18
      • 1970-01-01
      相关资源
      最近更新 更多