简体   繁体   中英

Using an MVC3 Application to call other MVC Apps

Actually I have some MVC3 Applications and I want to call this applications from a main MVC3 application. For example calling a action in a specific controller from the base MVC3 application.

Is there any idea for doing this?

You can use areas to structure a big site in smaller chunks.

From MSDN:

The MVC pattern separates the model (data) logic of an application from its presentation logic and business logic. In ASP.NET MVC, this logical separation is also implemented physically in the project structure, where controllers and views are kept in folders that use naming conventions to define relationships. This structure supports the needs of most Web applications.

However, some applications can have a large number of controllers, and each controller can be associated with several views. For these types of applications, the default ASP.NET MVC project structure can become unwieldy.

To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas. Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas).

For example, a single large e-commerce application might be divided into areas that represent the storefront, product reviews, user account administration, and the purchasing system. Each area represents a separate function of the overall application.

Source: http://msdn.microsoft.com/en-us/library/ee671793.aspx

In Visual Studio just right click in your project and say "Add area" to add a new area.

If you need to reference another area from your View you just add an "area" parameter to the route value collection:

@Html.ActionLink("[LinkText]", "[ActionName]", "[ControllerName]", new { area = "[AreaName]" }, null);

Controllers are just classes, so you should be able to instantiate them and call their actions as if they were part of your application layer.

Another idea, if you are early on in the development, consider looking into MVC4s WebAPI. If you can convert the sub-application's controllers to ApiControllers, then you would have the start of a service layer that the main application could call.

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