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?

3
  • Have you tried? It's my understanding that MVC will search for MyController in all references. Commented Jul 30, 2009 at 12:49
  • Check this: - SO - asp.net mvc put controllers into a separate project Commented Jul 30, 2009 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. Commented Jul 31, 2009 at 12:02

2 Answers 2

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).

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

2 Comments

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).
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.
0

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

1 Comment

Continued from previous Further going by the below link stackoverflow.com/questions/401376/… 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.

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.