URL-.NET Core 3.1 中带问号的格式
URL-Format with question mark in .NET Core 3.1
我有一个控制器,这个 url 对我来说很好用:
https://localhost:44332/api/thebest/dosomething/test
我正在寻找一种方法将简单的表示法转换为带有问号和参数名称的 URL,如下所示:
https://localhost:44332/api/thebest/dosomething?text=test
这怎么可能?非常感谢。
您的操作现在可能如下所示:
...
[HttpGet("{text}")]
public ActionResult Test([FromRoute]string test)
要调用它,您只需调用:https://localhost:44332/api/thebest/dosomething/test
得到你需要的结果:https://localhost:44332/api/thebest/dosomething?text=test
调整动作如下:
[HttpGet]
public ActionResult Test([FromQuery]string test)
我有一个控制器,这个 url 对我来说很好用:
https://localhost:44332/api/thebest/dosomething/test
我正在寻找一种方法将简单的表示法转换为带有问号和参数名称的 URL,如下所示:
https://localhost:44332/api/thebest/dosomething?text=test
这怎么可能?非常感谢。
您的操作现在可能如下所示:
...
[HttpGet("{text}")]
public ActionResult Test([FromRoute]string test)
要调用它,您只需调用:https://localhost:44332/api/thebest/dosomething/test
得到你需要的结果:https://localhost:44332/api/thebest/dosomething?text=test
调整动作如下:
[HttpGet]
public ActionResult Test([FromQuery]string test)