【问题标题】:How to hide unused id from URL routing in MVC?如何从 MVC 中的 URL 路由中隐藏未使用的 id?
【发布时间】:2022-10-07 17:21:29
【问题描述】:

实际上,我的参数可以为空。那么如果它是 null ,我该如何隐藏。 我想在控制器端处理

[Route(\"2\")]
    [HttpGet]        
    public ActionResult Index(string eID)
    {
       return view();

    }

The url i\'m getting like  /2?eID 
My eID can be null. I want to hide if eID is null in URL

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


    【解决方案1】:

    定义以下路线:

    [HttpGet("/2/{eID?}")]
    public ActionResult Index(string eID)
    {
       return view();
    }
    

    {eID?} 中的 ? 字符将 eID 定义为可选。

    因此,您可以使用以下 URL:

    • /2
    • /2/some-text
    • /2?eID=some-text

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2020-06-30
      • 2016-09-20
      • 2012-08-15
      相关资源
      最近更新 更多