Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

c# data annotations validade Model, out of context of form binding (upload file)

$
0
0

I’m using asp.net core 3.1 razor pages and wanna validade a model on a upload process using data annotation.

My model is:

public class UserUpload
{
[Key]
public string UserId { get; set; }

[Required(ErrorMessage = "email must be informed"), DataType(DataType.EmailAddress)]
public string Email { get; set; }

[Required, MaxLength(100, ErrorMessage = "Maximum for name is 100 chars")]
public string Name { get; set; }

[Required]
public string Status { get; set; }
}

Processing each line of the file uploaded how can I use data annotations to validade records and get all errors?

I have a crud for the same model and validations are processed by the framework resulting ModelState identifying all errors but I don´t know how to use the same mechanism in the mass upload data.

Tks


Viewing all articles
Browse latest Browse all 9386

Trending Articles