Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
RESTful Day #3: Resolve dependency of dependencies using Inversion of Control and dependency injection in ASP.NET Web APIs with Unity Container and Managed Extensibility Framework (MEF)[^]

I follow these pattern
But at last i stuck how to use
Model validation with attributes
I'm new in MVC
Please help me

What I have tried:

I use in these way
if (productToValidate.Name.Trim().Length == 0)
                _modelState.AddModelError("Name", "Name is required.");



But if I have larger entries then?
Posted
Updated 2-Jun-18 1:03am
Comments
Richard Deeming 22-May-18 12:05pm    
If you have a question about the code in an article, then post it in the forum at the bottom of the article.

That way, the author will be notified of your question, and will have a chance to respond.
Surendra_Singh 22-May-18 12:12pm    
I'm sorry sir
But i need to perform model validation i just use this article as examples
F-ES Sitecore 22-May-18 12:20pm    
Why don't you just use the relevant attributes like [Required] etc?

1 solution

i`m done by using auto mapper
like this way

Make Model In Model Folder


and map in controller

var product = _productServices.GetProductById(id);
          Mapper.Initialize(cfg => cfg.CreateMap<ProductEntity, ProductModel>());
          var itemModel = Mapper.Map<ProductEntity, ProductModel>(product);


var product
In this i get all data from service layer

then mapping is done by automapper and final data i will get in
itemModel 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900