1
routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
  new { controller = "My", action = "MyFolder", id = "" } // Parameter defaults
);

The above code will help invoking the view which is in MyFolder action which is in the MyController of the same project.

What if the MyController is in different project in the form of a dll, which I have included in my active project. How to invoke the respective View?

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • Have you tried? It's my understanding that MVC will search for MyController in all references. – James S Jul 30 '09 at 12:49
  • Check this: - [SO - asp.net mvc put controllers into a separate project](http://stackoverflow.com/questions/401376/asp-net-mvc-put-controllers-into-a-separate-project) – eu-ge-ne Jul 30 '09 at 17:43
  • continued from prev: Please do consider the below points: Maintainability Scalability Incremental development (Let's say we have certain functions in a separate dll alltogether which are very usefull in my project (example would be implementation of virtual Earth)) By having ControllerFactory we are immitating the Interface-Implementation design which is very beneficial w.r.t the above points. – PadmakarKulkarni Jul 31 '09 at 12:02

2 Answers2

1

If the MyController controller class is in a different project, then the route creation will fail, because when the application starts, MVC reflects all classes in the executing assembly with the postfix 'Controller'. If it cannot find the corresponding controller name, the app will fail to start.

I have attempted to move/access the controller in a different project (a good example would be in an admin tool project where you might want to separate some aspects of the app). This resulted in errors.

If anyone knows that this isn't right, then please let me know, because I would love to be proved wrong on this one. All my observations and work however, point to the conclusion that it doesn't (even if the two projects are in the same solution).

Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
  • Thanks people for that explanations. I was googling out all these days and side by side trying different ways of doing this. But now I guess I have a better understanding. One last question to put an end to this topic: Having understood the fact that the MVC pattern is all about separating the concerns, the models have to be separated out from the default location (I understand its not mandatory). – PadmakarKulkarni Jul 31 '09 at 11:59
  • The models can be seperated out from the default location. They don't need to be sat in the same project as your MVC site. I have a couple of personal sites where this is the case. It shouldn't matter where they are. – Dan Atkinson Jul 31 '09 at 12:15
0

What Dan said is correct. To use controllers in another project, you need to extend the DefaultControllerFactory.

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53
  • Continued from previous Further going by the below link http://stackoverflow.com/questions/401376/asp-net-mvc-put-controllers-into-a-separate-project Let me know, is it a good design to separate out the Controller as well in the form of ControllerFactory or the current place provided by ASP.NET MVC is the best one. – PadmakarKulkarni Jul 31 '09 at 12:01