Dane O'Connor
Dane O'Connor

Reputation: 77348

Where should I put my asp.net-mvc strongly typed viewdata?

I've been nesting my viewdata classes inside my controllers and, as their numbers grow, I'm starting to ask myself if this is a good idea. Then again, something about polluting the /Views and /Controllers directories with these things seems off.

Is there a convention I'm missing here? Maybe a /ViewData directory? idk, what are some good locations for my viewdata classes?

Upvotes: 6

Views: 444

Answers (4)

Richard
Richard

Reputation: 22026

since you are using MVC and the folder structure should represent the namespace structure of your code I would recommend for each of your object domains you should group your controllers, models and services into seperate folders

we would use

  • DomainName

         Controllers
         Model
         Services
    

Upvotes: 0

ajma
ajma

Reputation: 12206

I did exactly what you're suggesting, I have my strongly typed viewdata living in /ViewData. I thought about putting it in the \Model directory but I don't like my projects having too many nested directories. the \ViewData is also what Kigg does.

Upvotes: 0

John Sheehan
John Sheehan

Reputation: 78152

I don't know of a convention. I just put mine under /Model/ViewModel/BlahViewModel.cs, etc. I wouldn't put them in a separate project until there was a specific need for that. It wouldn't be difficult to move them later on if needed.

Upvotes: 3

mookid8000
mookid8000

Reputation: 18628

I put my view data classes in a project dedicated to just that. They are DTO's, and putting them in their own project enforces that they do not depend on anything above in the architectural layers.

Using them as DTO's to deliver to views is just one way of putting them to use. I might send them over the wire some time, inside a message on a service bus or whatever.

Upvotes: 0

Related Questions