tags:

views:

106

answers:

3
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?

+1  A: 

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
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
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
A: 

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

Wyatt Barnett
Continued from previousFurther going by the below linkhttp://stackoverflow.com/questions/401376/asp-net-mvc-put-controllers-into-a-separate-projectLet 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
A: 

Check this:

eu-ge-ne
continued from prev:Please do consider the below points:MaintainabilityScalabilityIncremental 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