【发布时间】:2021-02-25 20:22:47
【问题描述】:
我可能在这里遗漏了一些东西,因为我是 F# 的新手,但是,我需要以下内容:
open Microsoft.AspNetCore.Mvc
[<ApiController>]
[<Route("[controller]")>]
type MyController () =
inherit ControllerBase()
//[<HttpGet(Name = "Ip")>] doesn't work neither.
[<HttpGet>]
[<Route("[controller]/[action]")>]
member _.Ip() =
"192.168.199.2"
网址:https://localhost:5001/my/ip 应返回:192.168.199.2。
我收到的错误消息是:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-389e8d2f6bc3a342a3754b5c5ce7915f-7e6e851c78f47c4f-00","errors":{"id":["The value 'ip' is not valid."]}}
【问题讨论】:
-
我无法重现您所看到的内容。我编写了一个香草 F# 类,它继承自
Controller并按照您的方式公开Ip,它工作正常。也许我们需要查看更多您的代码?我假设您并没有在 URL 中使用字符串“”,对吗?它应该是您的实际控制器的名称。 -
@brianberns 我已经编辑了这个问题。事实上,我的控制器继承自 ControllerBase。