Jua*_*ino 5 f# asp.net-core-mvc
有没有办法让 mvc 模型拥有一个 f# 选项类型的属性,并在 Post 期间将其绑定到模型(就像当前映射的可空属性一样,但不是 null/value,而是 F# 的 Some 和 None) ?
f# 模型示例:
[<CLIMutableAttribute>]
type Student = { StudentId : int; MainSportsId : int option}
Run Code Online (Sandbox Code Playgroud)
然后在控制器的post方法中:
[<HttpPost>]
member this.AddRecord(resp: Student) =
resp.MainSportsId
Run Code Online (Sandbox Code Playgroud)
如果用户在文本框中输入数字,则 resp.MainSportsId 将为“Some number”;如果文本框为空,则 resp.MainSportsId 将为“None”。
谢谢你!