【问题标题】:How to specify a custom route name for razor page如何为剃须刀页面指定自定义路由名称
【发布时间】:2022-10-16 01:38:11
【问题描述】:

有没有办法为剃须刀页面指定自定义路由名称?

例如,对于控制器和操作,可以像这样使用RouteAttribute

[Route("my-custom")]
public class MyCustomController
{
    [Route("my-index")]
    public IActionResult MyIndex() => View();
}

是否有关于剃须刀页面的类似方法?

【问题讨论】:

    标签: c# asp.net-core asp.net-core-mvc razor-pages


    【解决方案1】:

    可以通过在 cshtml 文件中自定义 @page 指令的路由模板来实现。
    例如在MyIndexPage.cshtml razor 页面中;

    @page '/my-index'
    @model MyIndexPageModel
    
    ...
    

    不要忘记开头的正斜杠(/)。

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 2020-02-20
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2020-05-30
      相关资源
      最近更新 更多