【问题标题】:Routing attribute with fixed parameter value in asp.net coreasp.net核心中具有固定参数值的路由属性
【发布时间】:2019-07-02 05:54:58
【问题描述】:

有什么办法可以在.net core中配置固定参数的属性路由

[Route("TermsOfUse")] // ex: i need push default routing with id = 5
public async Task<IActionResult> Details(int id) { }

我找到了使用 routes.MapRoute 的方法

routes.MapRoute(null, "TermsOfUse", new { controller = "Article", action = "Details",  id=5 })

如何使用属性路由?

【问题讨论】:

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


    【解决方案1】:

    你可以这样做:

    [Route("TermsOfUse/{id=5}")]
    public async Task<IActionResult> Details(int id) { }
    

    如果没有提供 id 的值,那么它将是 5。

    【讨论】:

      猜你喜欢
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 2017-03-02
      相关资源
      最近更新 更多