Combine 2 Solutions in to 1

Malam Malam 226 Reputation points
2024-06-12T05:31:39.46+00:00

I have 2 separate MVC applications (Project1.sln, Project2.sln) using Entity Framework in VS 2019. Both applications work fine if the project/solution is loaded separately. When I add Project2 in Project1, I get a long list of errors.

What's the best way to combine these two projects in to one solution?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,408 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 28,831 Reputation points Microsoft Vendor
    2024-06-12T06:59:22.35+00:00

    Hi @Malam Malam,

    When I add Project2 in Project1, I get a long list of errors.

    How do you add Project2 to Project1?

    What's the best way to combine these two projects in to one solution?

    Maybe you can try using Area. Area allows us to divide a large application into smaller units, each unit contains a separate MVC folder structure, the same as the default MVC folder structure.

    Here is a simple example.

    Creating an Area

    right click on project Add -> New Scaffolded Item -> MVC Area.

    User's image

    User's image

    each area includes the AreaRegistration class. The following is adminAreaRegistration class created with admin area.

    public class adminAreaRegistration : AreaRegistration 
    {
        public override string AreaName 
        {
            get 
            {
                return "admin";
            }
        }
        public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "admin_default",
                "admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }
    

    The AreaRegistration class overrides the RegisterArea method to map the routes for the area. In the above example, any URL that starts with the admin will be handled by the controllers included in the admin folder structure under the Area folder. For example, http://localhost/admin/profile will be handled by the profile controller included in the Areas/admin/controller/ProfileController folder.

    Finally, all the areas must be registered in the Application_Start event in Global.asax.cs as AreaRegistration.RegisterAllAreas();.

    So in this way, you can create and maintain multiple areas for the large application.
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. SurferOnWww 2,411 Reputation points
    2024-06-13T00:33:26.3733333+00:00

    What's the best way to combine these two projects in to one solution?

    You should solve the issue in your previous thread https://learn.microsoft.com/en-us/answers/questions/1693568/how-to-call-another-view-from-one-view-in-mvc

    The answers are there.

    0 comments No comments