2

I have four layer solution a medium size project:

  1. Model (EF POCO entities)
  2. Data (EF ObjectContext)
  3. Services
  4. asp net MVC question

    a)Should i have validation attributes- Dataanotation in Models or MVC project?

    b)where should i set ViewModel-s if in MVC then where do i fill ViewModels with data, in Controller? else if on other project should create Repository for VewModel?

    c) should ViewModel have validation>?

3 Answers 3

2

A, C) If you have view models that are different from your DTOs, then you might prefer to use DataAnnotations in both types. This way, you can validate before you try to persist and again as you persist in case your DTOs are used outside the scope of your MVC app.

B) I usually tuck my view models into the Models folder of my MVC app and my DTOs into a data project that is separate from my MVC app. I use AutoMapper a LOT to copy values between my view models and my DTOs.

Sign up to request clarification or add additional context in comments.

Comments

0

It's okay to have validation on Models and ViewModels. It's on you what you like more, but it's better to have validation on ViewModels (you don't need to use binding and so), but there is more work with creating lot's of ViewModels when Models can be used too.

Comments

-1

I really prefer to create two folder inside the models:

One is for Database model class and another is for view models.

You can also add all type of validation into the database model class.

2 Comments

how does this related to the question ?
I did answered regarding to the model and view model, before validation i talk about how it could be map then validate in model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.