3,032 questions
0
votes
0
answers
81
views
How to return data annotations error message in one string?
I'm using data annotations from System.ComponentModel.DataAnnotations in my ASP.NET project. I get an error message where you can describe the requirements such as "Name is required" and etc....
1
vote
1
answer
93
views
Validation attribute validates but does not show error message
I created a custom validation attribute:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class MinByteLengthAttribute(string lengthPropertyName) : ValidationAttribute
{
...
1
vote
1
answer
66
views
How do I define a C# / ASP.NET MVC String class with a MaxLength that works with Entity Framework Core?
I would like to define a class for different strings which Entity Framework Core will recognise and apply certain rules without data annotations.
For instance I would like to replace the following ...
1
vote
0
answers
25
views
Data annotation date validation failed when using Safari in ASP.NET Core 9
I have this field, EXP_DEL_DATE, which is defined in a class as follows :
[BindProperty]
[Required(ErrorMessageResourceType = typeof(MsgsResource), ErrorMessageResourceName = MandatoryFld)]
[...
2
votes
0
answers
114
views
Validation and the required modifier
I'm working on an ASP.NET Core Minimal API. We are using the MiniValidation library for request validation on our endpoints. We have some strict linting that means for reference types we need to ...
1
vote
1
answer
56
views
After input all the values still showing username and password required in Blazor webassembly
I'm working with a Blazor web assembly project, but having an issue while submitting form after inputting email and password still asking for email and password
Email is required
Password is required
...
0
votes
1
answer
72
views
Custom Data Annotations Validator doesn't display ErrorMessage
Here's my custom validator:
public class CustomRuleFileTypeAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value,ValidationContext validationContext)
...
0
votes
2
answers
106
views
DataAnnotations being ignored in Blazor server-side .NET 9 page
I have a new .NET 9 Razor page Blazor server-side project.
I used EF Core Power Tools to import my database schema and generate the DbContext and model classes.
I created a MetaData class for one of ...
0
votes
1
answer
59
views
DataAnnotations validation messages still in English after setting pt-BR culture
I'm trying to get data annotations validation messages in Portuguese (pt-BR) but they remain in English even after setting the culture.
Here's what I've tried - in Program.cs:
var builder = ...
2
votes
1
answer
165
views
How can I export an excel file with highlighting and comments in R? [duplicate]
I would like to know if there is a way to export a data frame/tibble from R as an .xlsx file with highlighting and comments added natively from the R console rather than post-processing in Excel.
I ...
0
votes
1
answer
66
views
EF .NET 6 Data Annotations with database-first: cannot make annotations work
Here's a model class (generated by scaffolding, nothing changed):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace ...
1
vote
1
answer
514
views
Data annotation how to change default error messages
I have read many topics on how to change the default error message language for form validation, but none are applicable to Net 8 with Razor pages (no MVC). My situation is a webapp in C# with razor ...
1
vote
1
answer
134
views
Blazor Validation Loop
I have a simple model called FooModel that has a single string property called Text.
I am attempting to use DataAnnotationsValidator to validate a collection of Models that are dynamically added to ...
0
votes
1
answer
102
views
down quality of mask with json data for train u net model
I want mask my images with json formats as data for training model of u net.
I use this below code to mask them:
import json
import numpy as np
import cv2
import os
# Path to the folder containing ...
0
votes
1
answer
81
views
How to combine 3 annotated datasets into one file for further processing?
I have a dataset annotated by three people, so now I have three files. This dataset is about tweets annotation. How can I combine this dataset into one file for further processing. The data set is an ...
1
vote
2
answers
204
views
NotMapped Attribute is ignored when used on List of object
I have this model:
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using MyProject.Class.Dto;
namespace SageApi.Model;
public partial class FArticle
{
...
0
votes
1
answer
277
views
Data annotations is not working as expected even after applying required attribute
I have a model class in .NET 6.0 and applied data annotations. I have extension class ApiRequestValidation that returns validationresults after checking the JSON in the request body.
using System....
0
votes
0
answers
73
views
How to manage race conditions with Data Validation in a 3-Tier architecture Web API
My web api has 3 layers: Controller, Service Layer, and Repository. This is accessed via a SPA.
Imagine the scenario where you have a form in the SPA that takes the First Name and Last Name and sends ...
0
votes
0
answers
92
views
Validation of string in list of string via regex in data annotation
I have a class Detail with a parameter of type List<string>
public class Detail
{
public int index { get; set; }
[MaxLength(50)]
[RegularExpressionList("^[a-zA-Z0-9א-ת@/\\.\\- !@...
0
votes
0
answers
96
views
How to manually handle model deserialization errors similar to data annotations
I have previously been tasked with trying to submit json data and files to a web api shown here in this problem. The issue is I do not want to create a custom model binder for every instance this ...
0
votes
2
answers
849
views
ASP.NET Core 8 Web API data validation ignores data annotations
I'm trying to get automatic data validation working in an ApiController but when the user sends incorrect/missing data a JSON deserialization failed error message is returned instead of the custom ...
1
vote
2
answers
515
views
Choose proper language for data annotations in ASP.NET
I'm trying to localize error messages for data annotations attributes. I created two resx-files:
DataAnnotationsLocalization.resx
> DataAnnotationsLocalization.Designer.cs
...
0
votes
1
answer
47
views
Validating multiple checkbox in ASP.NET MVC
I have 4 checkboxes in my form and want user to select at least one of the checkbox when form is submitted.
I am using ExpressiveAnnotations.Attributes; reference as we use this in other part of ...
1
vote
1
answer
131
views
Multiple ways of writing DataAnnotations custom validators
I wrote a custom DataAnnotations validator (for client and server):
public class CustomAttribute : ValidationAttribute, IClientModelValidator { /* ... */ }
However the docs show an alternate approach,...
0
votes
2
answers
44
views
StringLengthAttribute does not enforce length
I have a property with StringLength attribute, but I can assign a string of any length to this property. I created the following test program in VB.NET 4.7 Framework:
Imports System.ComponentModel....
0
votes
0
answers
100
views
Workaround for compile-time constant requirement in ASP.NET Core DataAnnotations
I have various config values defined in the database or appsettings. But those cannot be used in DataAnnotation attributes (which require compile-time constants), so everything is duplicated in a ...
0
votes
1
answer
612
views
ValidateOnStart() and [Required] don't seem to work
I have an appsettings.json with the following contents:
{
"Settings": {
"Greeting": "Hello World"
}
}
that I associate with
public sealed class ...
7
votes
2
answers
5k
views
Using DataAnnotation Model Validation in Minimal Api
I am porting an application from Asp.net Controllers to Asp.net Minimal-Apis. The current project is using model-based DataAnnotations. Controllers do model validation out of the box but MinApi does ...
1
vote
2
answers
1k
views
How can I get access to MaxLengthAttribute Class to obtain the LENGTH value of a field during validation?
In the handleSubmit-function of a Blazor CRUD component, I have to provide an error message that is based on the DataAnnotation MaxLength-attribute. I would like to show a "custom" C# error ...
1
vote
1
answer
134
views
How to add localization for default data annotations validation error messages in ASP.NET Core 6 MVC?
The idea is to make use of the default messages for fast development of apps and for cleaner code, but I couldn't figure out a way to do it.
This is how far I got:
// Program.cs:
using ...
var builder ...
0
votes
1
answer
170
views
how to DbContextBulkExtensions.BulkUpdate with ConcurrencyCheck
I have situation when I have 2 pods that getting requests to update status of object lets call him user, he have 3 statuses : new, verified and failed.
they getting in parallel the entity with status ...
1
vote
0
answers
43
views
SwaggerUI custom ValidationAttribute not working on client's validation in Asp.Net Web API
Problem:
I wrote derived class from DataAnnotation.StringLengthAttribute attribute that allows exact number of characters instead of Min/Max.
enter image description here
My string:
enter image ...
0
votes
1
answer
154
views
How to change the annotation of data resulted by Yolov8?
I have a huge number of images that have human.
after a ran Yolov8 on them, all resulted labels are class 0 "person"
I want to change to 3 classes class 0 "man", class 1 "...
1
vote
1
answer
81
views
.NET RegularExpression DataAnnotation Attribure Not Matching Correctly
I can find plenty of information on Regular Expressions for .NET, but not specifically for the RegularExpression attribute. From what I can see, it behaves differently than normal .NET RegEx.
I am ...
0
votes
1
answer
50
views
DbContext.OnModelCreating - Reading custom attribute for each DbSet
I have a IdSeqAttribute:
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class IdSeq(string seq) : Attribute
{
public string Seq = seq;
}
and use it like ...
1
vote
0
answers
264
views
MudBlazor fluent validation when disabled using .when(), then DataAnnotation validation is in effect
I use fluent validation for client side validation of my mudform:
<MudBlazor.MudForm Model="person" @onsubmit="ValidSubmit" @ref="frmMain"
@bind-...
-2
votes
2
answers
97
views
Regular Expression for A-Z, Dash using Data Annotations
I need a regular expression for a URL-friendly slug, which can only contain lowercase letters and hyphens. It can't start or end with a hyphen and can't have more than one consecutive dash.
It will be ...
2
votes
1
answer
296
views
The DataType and Range data annotations do not localize the error message
I don't understand why in an asp.net 7.0 razor pages application the localization of data annotations error messages works for all attributes except for the "DataType" attribute where the ...
0
votes
1
answer
114
views
System.ComponentModel.DataAnnotations 2023
What's changed? I've had this C# Razor app (SQL backend) developed and deployed in production for 3 years now. Recently, I've added 3 new tables in SQL and rather than use Package Manager console to ...
1
vote
1
answer
92
views
Disable data annotation for specific DTO
I would like to disable data annotation validation for some case. You assume that we have two DTO and two endpoint
public class CreateBulkProductDto
{
[Required]
public List<...
0
votes
0
answers
84
views
My [Column(TypeName="varchar(10)")] does not work
I set attribute to benefitID to [Column(TypeName="varchar(10)")] but when I run it benefit is nvarchar(450).
[Key]
[Column(TypeName="varchar(10)")]
[StringLength(20)]
[Required]
...
1
vote
1
answer
418
views
ASP.NET MVC tightening up password requirement using MembershipPasswordAttribute
I am working on tightening up the password on my site, and wanted to see if I can use the MembershipPassword? I have tried to use the code below in my model but I am not getting any error message. ...
0
votes
0
answers
36
views
Can't get dropdown to appear after creating entity
I just wanted to be able for a user to select from a dropdown if their id number was a ssn or ein.
I created a Farm entity and I wanted the user to select from a dropdown using Datalist whether or not ...
-1
votes
2
answers
128
views
Validation attribute when set value from server side .Net Core [duplicate]
When I set value from server side to prop has a validation attribute "MaxLength", the application not throw exception.
public class Student
{
public Guid Id { get; set; }
...
3
votes
0
answers
905
views
PasswordPropertyText vs DataType(DataType.Password) attribute
What exactly is the difference between these two .NET attributes:
[PasswordPropertyText] => PasswordPropertyTextAttribute
[DataType(DataType.Password)] => DataTypeAttribute with a DataType ...
0
votes
0
answers
270
views
How to localize the property names in the error messages in the ASP.NET Core 7 Web API response?
I have gone through quite a bit of SO questions like:
Localise Display DataAnnotation without the Name Attribute in .NET Core 5 ViewModel
Display Name is problem on Data Annotation ErrorMessage (The {...
0
votes
0
answers
21
views
Exception to the rule - how to override a required attribute on one item when using data annotations with a list [duplicate]
I have a list of objects for my ASP.NET MVC model List<NameAddressModel>. In this abbreviated example, we're only looking at the first name. The model has the [Required] attribute, which will ...
1
vote
1
answer
403
views
Blazor DataAnnotations Compare validation conflicts with browser autocomplete
I have a Blazor server app that has a form with two password inputs, "new password" and "confirm password". I'm using DataAnnotations Compare attribute to validate that the two ...
0
votes
1
answer
588
views
DataAnnotationsModelMetadataProvider in ASP.NET Core 6.0
I am migrating a project from ASP.NET MVC to ASP.NET Core 6.0.
I have the following class in the ASP.NET MVC project:
public class CustomModelMetadataProvider : DataAnnotationsModelMetadataProvider
{
...
0
votes
1
answer
97
views
Annotating text data with ontologies
I have a list of plant organisms (text) and I want to annotate them with ontologies(Plant ontology, Crop Ontology, Food Ontology, etc), I was using ontology lookup services to do the annotation ...