简体   繁体   中英

ASP.NET MVC architecture

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM