tags:

views:

107

answers:

1

I would like to group all my Controllers with related Views in separate folders. How can I achieve this?

+4  A: 
  1. Don't.
  2. But if you must, write a custom ViewEngine to locate the views. I wrote a (now out of date) example here. ViewLocator has since been renamed to ViewEngine.
  3. See (1)

Update: If you actually meant you're looking for an "areas" feature, try this.

Craig Stuntz
I think he means the same thing as areas in monorail, which there is nothing wrong with so I have no idea why you say don't.
Mike Geise
Areas don't work that way; perhaps it's what he really meant, though. See http://blog.codeville.net/2008/11/05/app-areas-in-aspnet-mvc-take-2/ for a good design for that.
Craig Stuntz
I definitely meant the concept of Areas highlighted by Phil Haack.
gugulethun
OK, then see the update / link.
Craig Stuntz
Why 1?, why don't?
Paco
Paco, Views shouldn't know about Controllers, so they should be in different namespaces, and hence different folders.
Craig Stuntz
But views shouldn't know about each other too.
Paco
Um, true, though I've never actually seen anyone have a problem with that. Making controller<->view dependencies incorrect is *common*, though.
Craig Stuntz
My views depend on controller because I use Html.ActionLink or Html.BeginForm. I don't understand what's bad about that.
Paco
That isn't a dependency. That's a string. Dependencies are different.
Craig Stuntz
I consider something depending on something else a dependency. A form is posted to a specific controller action and it doesn't matter if a string or generic with lambda is used.
Paco
I'm not sure yet if I want to create a directory with controller/viewmodel/view or a directory per type like the default
Paco
My $0.02: Use the default unless you have a *really* good reason not to. About dependencies: I think we'll just have to disagree on that.
Craig Stuntz