hasrthur
hasrthur

Reputation: 1490

ASP.Net Core and model validation

Suppose I have a model which I need to validate. I can add some validate attributes to the properties I want to validate. And it works pretty fine. But at some point I want to validate this model depending on other models (I will need t query db). And here there are some options.

_

if (Model.IsValid) {
    if(!await Manager.Create(myModel)) {
        Model.CopyErrors(Manager.Errors); // Extension method for Model
    }
}

So what is the correct way of handling such a situation?

P.S. I am using asp.net core and entity framework core

Upvotes: 1

Views: 1472

Answers (1)

tchelidze
tchelidze

Reputation: 8318

What you need is Fluent Validation

Upvotes: 1

Related Questions