Home Moving an ASP.NET MVC Project into "Areas"
Reply: 0

Moving an ASP.NET MVC Project into "Areas"

Mustafa Asım Yaylakaşı
1#
Mustafa Asım Yaylakaşı Published in 2017-11-13 09:06:20Z

I've made an admin panel using MVC 5 but I didn't use "Areas" method while building it. Now I want to move it into the "Areas/Admin". I'm a newbie so I don't know if is there any easy way to do this.

Can you help me? (I've searched for it and I didn't find anything helpful for me.)

EDIT: I've figured it out by myself.

First of all, in solution explorer right click on your project and click add->New Scaffolded Item. Under the MVC tab click the "Area" and click "Add". Give a name to your area (I've named it as Admin).

1- I've cut my Controllers and paste it into "Areas/Admin/Controllers".

2- I've cut my Views and paste it into "Areas/Admin/Views".

3- I've cut my Models and paste it into "Areas/Admin/Models".

4- Your connection string will change after doing 3rd step. (Don't forget it.)

5- Change "Areas/Admin/Views/_ViewStart.cshtml" file as

@{
            Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    }

and paste it into "Areas/Admin/Views"

6- Open your Controllers and check them one by one and change these:

using ProjectName.Models;
namespace ProjectName.Controllers

to these:

using ProjectName.Areas.Admin.Models;
namespace ProjectName.Areas.Admin.Controllers

7- Open your Views and check them one by one if you have something like this @model ProjectName.Models.users change it to this @model ProjectName.Areas.Admin.Models.users

8- You have to change the "RouteConfig.cs" and the "AdminAreaRegistration.cs" files as shown in this link : Mvc area routing?

In this step, I changed my AdminAreaRegistration.cs file as shown in the link but it didn't worked and I changed it like this:

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "Account", action = "Login", id = "" }
        );
    }

And finally it worked.

That's all, I hope this will be helpful for you...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301257 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO