簡體   English   中英

F# Giraffe 簡單 model 驗證基於屬性

[英]F# Giraffe simple model validation based on attributes

F# Giraffe 提供了自己的驗證機制,不同於基於標准 ASP.net 屬性的驗證機制。 那么如果可能的話,我如何在 Giraffe 中使用基於屬性的驗證呢?

這里來自 github https 的回答://github.com/giraffe-fsharp/Giraffe/issues/436

 open System.ComponentModel.DataAnnotations;
    open System.Collections.Generic;

    let validateDataAnnotations (object:obj) =
        let ctx = new ValidationContext(object)
        let errors = new List<ValidationResult>()
        if Validator.TryValidateObject(object, ctx, errors, true) then None
        else Some errors

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM