![](/img/trans.png)
[英]Is dbContext (retrieved from ValidationContext.GetService in Blazor Server Side app) thread safe?
dbContext(從 Blazor 服務器端應用程序中的 ValidationContext.GetService 檢索)線程安全嗎? ...
[英]Is dbContext (retrieved from ValidationContext.GetService in Blazor Server Side app) thread safe?
dbContext(從 Blazor 服務器端應用程序中的 ValidationContext.GetService 檢索)線程安全嗎? ...
[英]Validation Context is always NULL
我已經實現了一個自定義驗證屬性來檢查列的唯一性。 我想檢查提供的值是否已存在於數據庫中。 這是我的代碼: IsValid 方法中的 validationContext 始終返回 null。 如何修復? Startup.cs:ConfigureServices 方法 Model class: ...
[英]Why should Custom Validation Attributes be sealed in C#
我正在嘗試為數據注釋創建自定義 C# 驗證屬性(沒有密封關鍵字)。 但是這里的 Microsoft 頁面顯示“使 class 不可繼承”。 為什么? 我是否通過允許“MyValidatorAttribute”class 可繼承而忽略了某些東西? ...
[英]Custom Validation Attribute for validation on another field in the Model example Shipped Qty Cannot be > Ordered Qty
我正在開發一個 ASP.Net core 3.1 MVC 項目,我想在其中創建一個自定義驗證器,其中發貨數量不能超過訂購數量。 我在 ViewModel 錯誤 CS0120 的 model ([ValidShippedQty(Pending)]) 中遇到編譯錯誤 非靜態字段、方法或屬性“Shipme ...
[英]Custom Validation Attribute: Comparing one property to another property's inner property
我有一個 class StarActivityModel,我想驗證 StarChange 的輸入值是否小於客戶的 StarCount 屬性。 為此,我嘗試創建一個自定義驗證屬性,但在獲取 StarCount 值時遇到了問題。 我對自定義驗證屬性的嘗試 ...
[英]Change Response Status Code from ValidationAttribute
在 aspnet 核心 web api 項目中,我有邏輯 分散在許多端點/控制器上。 我想將這個橫切關注點重構為一個屬性,例如一個 ValidationAttribute: 在 controller 中嘗試應用: 盡管這似乎不起作用- 端點仍將返回 400 Bad Request。 是否可以/建議在 ...
[英]Add Custom ValidationAttribute to Swagger Documentation
我有一個自定義驗證屬性 假設我有一個實現 ValidationAttribute 的 HelloWorld 類。 然后我將此屬性應用於我的 API 中的一個字段。 當我生成 Swagger UI 時,我得到一個 JSON OpenAPI 規范,模型顯示每個字段的屬性,如下所示: 如果我添加 ...
[英]Customs validation attribute with multiple value for Blazor EditForm validations
我想檢查 A 列和 B 列的組合在我的 blazor 應用程序中是否唯一。 使用ValidationAttribute檢查 A 列是否唯一非常簡單 但是,當涉及多個值時,我不知道如何做同樣的事情。 假設我想檢查 Code + Name 在數據庫中對於以下MyClass2是否唯一。 我試過使用自定義參 ...
[英]How to create custom validation attribute for Iranian national code in asp.net core?
我正在嘗試驗證 asp.net 內核中的國家代碼。 我找到了驗證代碼,當我將其用作方法時它可以工作,但我想將其創建為驗證屬性。這是我在屬性 class 中的代碼: 這就是我使用它的方式。 它在視圖模型 class: 我運行該應用程序,例如我輸入 1111111111 作為國家代碼,但它沒有顯示任何 ...
[英]How can I cleanly share a Custom Validator (ValidationAttribute) for a data model, a ViewModel, and a DTO in ASP.NET
我正在學習 ASP.NET MVC 課程。 我正在使用 Z9E0DA8438E1E38A1C30F4B76CE8Z API 標准構建 REST Web API 標准還包含應用程序。 我正在使用 DTO(數據傳輸對象)將 API 與數據 model 分離。 我已經創建了一個自定義 Validatio ...
[英]Placeholder in constructor chaining?
我正在瀏覽一個材料,自定義驗證邏輯的代碼如下:-public class MaxAttribute : ValidationAttribute { public MaxAttribute(int maxWords) : base("{0} has too many words.") { ...
[英]In net 5, when binding from body, how to specify that all properties must be present?
像 BindRequired 這樣的屬性使操作參數成為必需的,甚至可以應用通常的 model 驗證屬性。 您如何要求 class 中的所有屬性出現在請求正文中? ...
[英]Override ValidationAttribute ErrorMessage, from string to new ErrorModel Class
我目前正在學習Net core,任何人都可以與我分享如何將dataAnnotation ErrorMessage從字符串覆蓋到object。 而不是 ErrorMessage 作為字符串 到 ErrorMessage 作為 object 我創建了一個 ErrorModel class 對於從 Va ...
[英]I need to return customized validation result (response) in validation attributes in ASP.Net core Web API
我需要在 ASP.Net core 中返回自定義的驗證結果(響應)失效屬性 Web API 這是我創建的 ValidationAttribute。 我創建了繼承 ValidationResult 的 CustomValidationResult object 以便我可以返回我自己的自定義響應: 但 ...
[英]C# Sharing ValidationContext across different ValidationAttribute fails
想要使用如下所述的一系列自定義驗證屬性對輸入模型應用驗證。 如果第一個驗證屬性的驗證結果,即“ValidatorAttributeOne”為真,則不需要處理“ValidatorAttributeTwo”驗證邏輯。 為了實現分配給“validationContext.Items”字典的“Valid ...
[英]ASP.NET Core empty validation string entry in array of errors?
當我們有一個動作時,接受以下參數: 當驗證失敗時,返回的對象有一個空條目,如下所示: } 這是為什么? 您能否參考導致此問題的來源? 我相信它與反射有關,即它們獲取對象的屬性,但在我們的例子中它是一個簡單的 int/string 對象,而不是自定義類型。 ...
[英]C# Razor page required attribute on IFormFile works only when clicking away
這里的目標是在點擊離開之前讓input="file" Required的驗證屬性起作用。 現在,當我要上傳 select 文件時,我必須點擊離開才能進行要求驗證。 結果我必須雙擊提交。 index.cshtml.cs 索引.cs ...
[英]How can I validate a property based on a value in a parent Model?
我有一個網站,人們可以在其中申請服務。 他們 select 是他們想要的產品和選項,以及有關他們自己的信息。 model分為幾部分:public class ApplicationInformationModel { public int ProductType { get; set; ...
[英]Blazor webassembly: How to pass a custom type parameter to a custom ValidationAttribute
如果我沒記錯的話,只有原始類型可以作為參數類型傳遞給定制的ValidationAttribute (例如string ): 並像這樣使用它: 但是,如果我們想將非原始類型傳遞給定制的ValidationAttribute怎么辦? 例如,如何將此 object 的實例傳遞給AttributeName ...
[英]How to implement validation rules for elements from a partial view
我們正在開發一個 .net 核心 3.1 MVC 應用程序(實際使用 MVVMC)。 我們已經實現了自定義驗證屬性。 並希望它們在服務器和客戶端上進行檢查。 該視圖是標准視圖,但用戶可以將多個局部視圖添加到標准視圖(通過按鈕)。 在局部視圖中,我們無法在輸入字段中使用“asp-for”標簽助手,因為 ...